From the comments:
I am sending to another site
Yeah! Your problem is there. Browsers block AJAX for external websites for security reasons. Sorry, but you are not going to issue this request using the XHR request.
If another website wants you to communicate with them, they could expose this part of the site through JSON-P, which works something like this:
- My site adds
<script src="http://othersite.com/signon.js?username=foo&password=bar&callback=myCallback"> to the source code (yes, it's useless to use GET for this, but JSON-P cannot work somehow in another way) and creates a function called myCallback to process the response data. - Another site signs up, then returns something like
myCallback({success: false, errorMessage: "Incorrect password, try again!"}) - This script runs on my site, calls
myCallback , and all is happy.
JSON-P is a powerful protocol, but only works if the remote site agrees with it. However, if they do, jQuery has a nice shortcut for it: just set dataType: "jsonp" and it will handle the whole callback function for you.
But if you are not closely associated with this site, it is unlikely to happen, and you probably just want to abandon this interaction between sites. Sorry, but such a cross-domain policy is crucial for online security. (I do not want other sites to issue bankofamerica.com requests on my behalf, thank you.)
source share