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.
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.