[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1132
  • Last Modified:

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);
      }
0
jackjohnson44
Asked:
jackjohnson44
  • 2
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
Try this :
$.post(loginUrl, function(responseText) { alert("success" + responseText); });
0
 
jackjohnson44Author Commented:
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);
      }
});
0
 
leakim971PluritechnicianCommented:
please provide a link to a simple page which reside on your site
0
 
jackjohnson44Author Commented:
Your answer will work.  I had an issue due to cross site scripting.  Thanks!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now