I feel like I should be able to find this anwser but have had zero success after hours of research. I have this page with a simple jquery ajax calls to a API service. It works fine in Chrome, Safari, and Firefox, and even IE 10. But IE 9 and 8 seem to fail.
Here's the code:
$.ajax({ type: "GET", url: "http://api.domain.org/api/campus?filtertype=name&filter="+ escape($('#campus').val()), dataType: "json", contentType: "application/json; charset=utf-8", success: function (result) { $('#results').children().remove(); var arrayd = (typeof result) == 'string' ? eval('(' + result + ')') : result; if (arrayd != null) { for (var i = 0; i < arrayd.length; i++) { $('#results').append('<li>' + arrayd[i].SchoolName + '</li>'); } } }, error: function (request, status, errorThrown) { alert("There was an issue with the request"); } // When Service call fails }); The biggest issue is that the alert files, but I can't see any traffic in the IE Debugging tools which doesn't help me see if I even hit the server.
I've tried a number of things:
- Setting $.ajax setting per http://mvcdiary.com/2013/01/16/jquery-ajax-request-not-working-in-ie9/
- Setting '$.support.cors = true;' before the ajax call
- Using 'jquery.iecors.js'
Update
After changing the dataType to 'jsonp' I started seeing the traffic in IE 8/9 with successful calls. However, I'm not getting any browser to call the success method now.
$.ajax({ type: "GET", url: "http://api.athletesinaction.org/api/campus?filtertype=name&filter="+ escape($('#campus').val()), dataType: "jsonp", async: false, contentType: "application/javascript", crossDomain: true, jsonpCallback: 'myTest', success: myTest, error: function (request, status, errorThrown) { alert(errorThrown); } // When Service call fails }); function myTest (argument) { alert("YEAH"); $('#results').children().remove(); var arrayd = (typeof result) == 'string' ? eval('(' + result + ')') : result; if (arrayd != null) { for (var i = 0; i < arrayd.length; i++) { $('#results').append('<li>' + arrayd[i].SchoolName + '</li>'); } } }
evaling the JSON? What happens if you useJSON.parse()instead? What does the JSON response look like? What console errors are you getting in IE?document.domain = "athletesinaction.org";may be needed.