2

this is my first question to the stack.

jQuery.ajax type: Post to an ashx file not being initiated in IE. works fine in FF, Chrome, and Safari

Code below:

$.ajax({
    type: "Post",
        url: "http://[ ... ]loguserdata.ashx?" + dataString,
        data: "",
        cache: "false",
        contentType: "text/plain",
        success: function(msg){
            //alert( "Data Saved: " + msg );
        }
});

by works fine in FF, etc. I mean the ashx file is called and info is logged. I can see the ajax call in fiddler, firebug and chrome's equivalent.

but there doesn't seem to be jackchit happening in IE9 or in IE compatibility mode.

I can get several versions of the code above to work in the other browsers. Including a $('#result').load( ...

but NOTHING works in IE

btw, works fine locally in IE.

oh, and I don't give a diddly poo about any return value.

and it's not a cache issue. I have a date=getTime() tacked onto the end of the querystring.

querystring (dataString) looks something like fname=john&lname=doedy

EDIT: I have solved this issue. I will post a thorough answer tomorrow when I have time.

mtntrailrunner
  • 761
  • 6
  • 11

3 Answers3

1

Long story truncated: You can't do a XMLHttpRequest crossdomain. Use jQuery's getJSON method with the querystring parameter &callback=? added to the url. This I believe converts the datatype to JSONP.

 var url = 'http://handlers.flowauto.com/eprice/loguserdata.ashx?fname=jim&callback=?';
        $.getJSON(url, function(data) {
            // do some stuff
        });

Here are a few links that helped me solve this.

XMLHttpRequest cannot load an URL with jQuery

http://api.jquery.com/jQuery.getJSON/ see excerpt below

JSONP If the URL includes the string "callback=?" (or similar, as defined by the server-side API), the request is treated as JSONP instead. See the discussion of the jsonp data type in $.ajax() for more details.

http://api.jquery.com/jQuery.ajax/ see excerpt below

Additional Notes: Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol. Script and JSONP requests are not subject to the same origin policy restrictions.

Community
  • 1
  • 1
mtntrailrunner
  • 761
  • 6
  • 11
0

Check your IE security, since it's work locally. I guess that files on the locahost have more privileges.

Edit:

IE9 prevent doing cross-domain ajax call, Opera browser too. For IE9 you can read this article, for a workaround. It suggest to use XDR (XDomainRequest) instead of the usual XMLHttpRequest.

Nettogrof
  • 2,116
  • 2
  • 15
  • 22
0

Try this since you aren't sending POST data:

$.ajax({
    type: "GET",
        url: "http://[ ... ]loguserdata.ashx?" + dataString,        
        cache: "false",
        contentType: "text/plain",
        success: function(msg){
            //alert( "Data Saved: " + msg );
        }
});
rick schott
  • 21,012
  • 5
  • 52
  • 81
  • Rick, this still only works in Chrome and FF, but not in IE. On a side note I just changed from an ashx file to an aspx file. Same thing. Works in Chrome and FF, but not IE – mtntrailrunner Oct 13 '11 at 14:27