Browser opens JSON response as a file
I have some jQuery which is just fine:
开发者_如何学Python$.ajax({
url: actionUrl,
type: "POST",
data: data,
dataType: "json",
success: function (data) {
alert(data)
}
});
However, instead of handling the data, the browser tries to open the file. Why?
I'm guessing there is anything wrong with the MIME type of the response, but it works pretty fine other places in the code.
could you possibly provide the link in actionUrl? Or is that private?
The code you've given is totally correct, so the problem must be with the server returning the wrong header for the return stream. The response header should be text/json. If it's in the format: "application/.." that would be incorrect.
You can view the the return headers for that url via tools like fiddler, poster (firefox addon), firebug (firefox addon), chrome developer view, etc..
Can you check and report back?
try
$.ajax({
url: actionUrl,
type: "POST",
data: data,
contentType:'application/json charset=utf-8',
dataType: "json",
success: function (data) {
alert(data)
}
});
精彩评论