score:14

Accepted answer

From the comments:

I'm posting to another site

Aha! There's your issue. Browsers block AJAX to external websites for security reasons. Sorry, but you're not going to issue that request via an XHR request.

If the other website wants you to communicate with them, they could expose this part of the site via JSON-P, which works something like this:

  1. My site adds <script src="http://othersite.com/signon.js?username=foo&password=bar&callback=myCallback"> to the source code (yeah, it's messy to use GET for this, but JSON-P can't work any other way), and creates a function named myCallback to handle the response data.
  2. The other site signs in, then returns something like myCallback({success: false, errorMessage: "Incorrect password, try again!"})
  3. That script is run on my site, calls myCallback, and everything is happy.

JSON-P is a powerful protocol, but only works if the remote site agrees to it. Still, if they do, jQuery has a nice shortcut for it: just set dataType: "jsonp" and it will handle the whole callback thing for you.

But if you're not closely involved with this website, that's unlikely to happen, and you'll probably just be stuck with having to give up on this kind of cross-site interaction. Sorry, but this kind of cross-domain policy is critical to online security. (I don't want other sites issuing requests to bankofamerica.com on my behalf, kthx.)

Similar question

score:-2

when using POST method you should ,in your case, Post your data as JSON

var url = "https://mywebsite/signon.php";
$.ajax({
    url: url,
    type: 'POST',
    dataType: 'html',
    data: {
      harv_acc : accountnumber,
      harv_eml : email
    },
    success: function (data) {
        closePopup("div_PleaseWait");
        alert(data);
        //window.location = encodeURI('<%= Url.Action("DownloadDocument", "Documents") %>?DocumentID=' + documentID + '&DownloadType=' + downloadType + '&DownloadPath=' + data);
    }
});

NOTE : i used dataType : JSON

score:0

Try sending ther data as a key:value object. This is an example from the jQuery docs

    $.ajax({
  type: "POST",
  url: "some.php",
  data: { name: "John", location: "Boston" }
}).done(function( msg ) {
  alert( "Data Saved: " + msg );
});

Update: as user Matchu pointed out, this is not the problem, as the data will be converted into a query string anyway, as stated in the jQuery docs:

"The data option can contain either a query string of the form key1=value1&key2=value2, or a map of the form {key1: 'value1', key2: 'value2'}. If the latter form is used, the data is converted into a query string using jQuery.param() before it is sent. "

So yeah, some rash answering on my part there. At least I learned something! ;)

score:0

Cross domain ajax requests are not supported by browser. But there is another way to get around this.

You can use JSONP for cross-domain requests. It is easy to use and allows you to request anything (as long as it is in JSON format) from any server/script that supports the callback. The good thing about JSONP is that it works in older browsers too.

The only serious limitation seems to be that it always uses the HTTP GET method

Can you please check with this too.

score:1

The first parameter passed to your complete function will be a jqXHR object, which is a wrapper around the browser's XMLHttpRequest object. A more convenient way to handle the response is to use the done method:

var url = "https://mywebsite/signon.php";
$.ajax({
    url: url,
    type: 'POST',
    dataType: 'html',
    data: "harv_acc=" + accountnumber + "&harv_eml=" + email
}).done(function(data) {
    closePopup("div_PleaseWait");
    alert(data);
});

Related Query

More Query from same tag