I have a problem that occurs in IE 8 and Firefox 6.0, but not in Chrome 17.0.9. When I post frmMain below, I post it to a test page that simply returns a simple JSON string with ContentType: application/json; charset=utf-8
ContentType: application/json; charset=utf-8
. The problem is that IE and FF will offer me to save the JSON that is returned from the server, and not hit the success method in my jquery code. But itβs strange if I omitted <input name='File_1' type='file' />
in the published form, then IE and FF will not tell me to save my JSON, and my jquery success code will run.
So, it seems that the hosted content has a footing (in IE and FF) about how the browser responds to the returned payload. Through Fiddler, I checked that in each case the returned payload is exactly the same.
Any ideas?
SOLUTION FOUND: See my answer below. From what I can compile, "text / html" is the best type of cross-browser content to return when jquery / ajax / json is executed.
THE CODE
<script> $(function () { $('#btnSave').click(function () { $('#frmMain').ajaxSubmit({ success: function (data, statusText, xhr, $form) { alert('test success'); }, fail: function (data, statusText, xhr, $form) { alert('test fail'); } }); }); }); </script> <body> <form id='frmMain' action='/test' method='post'> file: <input name='File_1' type='file' /><br /> name: <input name='json' value='{"id":5}' /><br /> <input type='button' id='btnSave' value='Save' /> </form> </body>
CALL WITH FILE DOWNLOAD (REASON FAULT):
CALLED WITHOUT A FILE DOWNLOAD (WORKS):
WHAT TO SEE IN IE:
WHAT YOU NEED TO SEE IN FF:
source share