I ended up fixing this after all, although I can't remember what specifically caused it to work... I believe it was omitting the contentType field, for whatever reason. (I know that cross-domain requests are quite restricted, but don't recall if this was the reason.)I do know that the cross-site nature of the call was making my IE8 not very happy, and Firefox, Chrome, Opera, Safari, and IE10 all worked with this code.Anyway, here is the working code:
if ('withCredentials' in new XMLHttpRequest())
{
/* supports cross-domain requests */
$.support.cors = true;
jqxhr = $.ajax(
{
url: "https://www.arcgis.com/sharing/rest/generateToken",
type: "POST",
data: {
"username": "thomas.chris.a",
"password": "<passwd here>",
"expiration": 15,
"referer": "http://localhost:8080/MFF/",
"f": "json"
},
dataType: 'json'
})
.done(function (resp)
{
// in most browsers the response will be a json,
// but in the event that it's a string (IE8-9) parse it.
var json = (typeof resp === "String" ? $.parseJSON(resp) : resp);
alert('token:' + json.token);
callback();
})
.fail(function (xhr, txt, err)
{
alert('get token failed...');
});
}
else
{
// Either the browser doesn't support cross-domain at all,
// or it's IE 8 or 9, and either way screw it. Use a real browser!
alert('Unable to send request to ArcGIS: \n'
+ 'No CORS Support available in this browser!\n\n'
+ 'For better results, use a modern version \n'
+ 'of Firefox, Chrome, Opera, or Safari.');
return;
}
I ended up restricting this particular functionality to any of the browsers which did work: that being any browser other than IE8/9. Thanks again, MS, for complicating things. The XDomainRequest type is what was screwing it up, after all. In my use-case, this is a piece of administrator functionality, so I'm allowed to make them use a browser that doesn't create its own web standards.I'm not sure what I would have done if I needed to support IE8. I tried just about everything, including overriding the ajax transporters and a few other really ugly solutions, to get this to work, with no results in IE8. I was working on this request for a full, full-time week. So... I'm officially done supporting IE8, sorry Windows XP.Thanks again for the help with that link! Hopefully posting this helps someone in the (distant)? future with this particular problem.