I have an ajax call that goes out to my rails server. Depending on the content type my rails server either responds with HTML or JSON. This works fine on the iPhone browser and on desktop browsers like chrome, etc. However on the Android browser somehow my server is not recognizing the content type. I don't think the overrideMimeType is working!
Anyone know of a workaround? If I can't figure it out I'll just have to create a special URL to handle the JSON requests.
Code looks something like this :
function makeAjaxCall {
xmlhttp=new XMLHtt开发者_Python百科pRequest();
targetUrl = window.location.pathname;
xmlhttp.open('GET',targetUrl,true);
xmlhttp.overrideMimeType("application/json");
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
// On android browsers only this responds with HTML when it should be JSON
alert('response:' + xmlhttp.responseText);
r = eval('(' + xmlhttp.responseText + ')');
// Do more stuff
}
}
xmlhttp.send();
}
Maybe you need
xmlhttp.setHeader("Content-Type", "application/json");
as well?
精彩评论