3

I'm trying to find if its possible to send POST to url using only html and javascript. According to this its not possible. Can anyone knowledgeable tell me is it possible ? and if it's how to do it? ad1 Without using jQuery

1

4 Answers 4

2

If you consider jQuery to be JavaScript it sure is.

See here:

http://api.jquery.com/jQuery.post/

If you're going to be doing a lot of this sort of thing in your development in the future, I'd highly recommend you get used to using jQuery.

2

If you really want to you can use XMLHttpRequest. All major browsers support it.

2

I'm trying to find if its possible to send POST to url using only html and javascript.

Yes

According to this its not possible.

No. The Same Origin Policy, in general, prevents you reading data from different origins. Pre-flight checks sometimes prevent you sending data, but there are several ways to circumvent the policy.

and if it's how to do it? ad1 Without using jQuery

XMLHttpRequest and jQuery.ajax are well documented.

-1

As per the article, if the URL is not in the same origin, it is not possible. This is for security reasons.

If it's within the same origin (domain) then it is possible.

Pure JS (no frameworks) examples here: http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

4
  • Hmm but its possible to send post to url from localhost using any known to me script language.
    – whd
    Commented Mar 5, 2013 at 16:12
  • 1
    @whd — There is a big difference between making an HTTP request from your server and making an HTTP request from your visitor's browser. You are responsible for your server, you are not responsible for your visitor's browser (your visitor is).
    – Quentin
    Commented Mar 5, 2013 at 16:15
  • But it isn't true that it isn't possible, there are a number of ways to circumvent the same origin policy. It is only impossible under default conditions when you are trying to make a straight request.
    – Quentin
    Commented Mar 5, 2013 at 16:29
  • the given link broken
    – Godwin
    Commented Jun 26, 2020 at 19:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.