开发者

returning JSON response to a ajax call prompts file download containing the response

开发者 https://www.devze.com 2022-12-15 03:30 出处:网络
i am submitting a from using jQuery ajax, and server is returning json response. but instead of the script, parsing the json result, the browser is prompting me to download the json response.

i am submitting a from using jQuery ajax, and server is returning json response. but instead of the script, parsing the json result, the browser is prompting me to download the json response.

I have had this problem before, where i forgot to return false at the end of the event han开发者_C百科dler. But this time im clueless why this is happening. anyone has experienced this problem.. thanks


If the browser is trying to download a file, it most probably related to content-type of your response. You are using something that the browser considers to be binary and unsafe. Try using text/plain, text/html, text/xml or something like it.


After some stumbling around, I solved my problem by including links to the following two jquery libs:

<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
0

精彩评论

暂无评论...
验证码 换一张
取 消