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
4 Answers
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.
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.
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
-
Hmm but its possible to send post to url from localhost using any known to me script language.– whdCommented 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).– QuentinCommented 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.– QuentinCommented Mar 5, 2013 at 16:29
-