Link to home
Create AccountLog in
Avatar of jackjohnson44
jackjohnson44

asked on

convert ajax xmlhttprequest to jquery ajax

Hi, I am trying to convert the following code to jquery, but I am having issues.  This uses cross site scripting, but I changed the setting on my browser.  I can successfully use the non jquery code.

      Ajax=new XMLHttpRequest();
        Ajax.open('POST', url, true);
      Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      Ajax.send(data);

Here is what I currently have:
jQuery.ajax({
      url: loginUrl,
      contentType: "text/html; charset=Windows-1256",
      dataType: "JSONP",
      async: true,
      success: function (responseText, status) {
            alert("success" + responseText);
      },
      error: function (xhr, ajaxOptions, thrownError) {
            responseText("error=" + xhr.status + "=" + thrownError);
      }
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of jackjohnson44
jackjohnson44

ASKER

Actually it might be working better than I thought.  It is not hitting my success area, but if I look in fiddler I can see a 200 response in the header, and the xml response in the text view.  For some reason, everything is working, but my error area is still being hit.

This is what I have:
var postData = {};
postData["source"] = source;
var loginUrl = url + "LogIn?source=" + source + "&version=" + version;
jQuery.ajax({
      url: loginUrl,
      //dataType: "xml",
      data: postData,
      async: true,
      type: "POST",
      success: function (responseText, status) {
            alert("ASDF");
      },
      error: function (xhr, ajaxOptions, thrownError) {
            responseText("xhr.status=" + xhr.status + "\najaxOptions=" + JSON.stringify(ajaxOptions) + "\nthrownError=" + thrownError);
      }
});
please provide a link to a simple page which reside on your site
Your answer will work.  I had an issue due to cross site scripting.  Thanks!