Note that there are some explanatory texts on larger screens.

plurals
  1. POFireFox and IE9 tries to download or show json-response instead of letting javascript parse it
    primarykey
    data
    text
    <p><strong>Update</strong></p> <p>My problem was that I used event.preventDefault() instead of return false to hinder the form from posting normally. FF and IE didn't like that and broke the JS by that line. I removed that and appended return false at the end and this solved the problem. Thanks to Darin Dimitrov for the extensive checklist.</p> <p><strong>Original question</strong></p> <p>I'm using ASP.NET MVC3 and jquery ajax to post json-data to the server and receive a response. However, when I'm using Chrome it reads the json-response normally, updating the divs that I want etc. With IE and FF it doesn't work though. They read just the response and shows only that on the page.</p> <p>I saw some other threads mentioning to define the mime type as "text/plain". This changed the previous behavior of prompting the user to download the json-response instead. </p> <p>This is the javascript for making the post:</p> <pre><code> $.ajax({ url: $("#formRegister").attr("action"), type: 'POST', data: JSON.stringify(user), dataType: 'json', contentType: 'application/json, charset=utf-8', traditional: true, success: function (data) { alertMessage(data.Message); }, error: function () { } }); </code></pre> <p>This is the ActionMethod receiving the call and returning a JsonResponse:</p> <pre><code>[HttpPost] public JsonResult Register(UserRegisterPackage package) { ClientAlert alert = new ClientAlert(); if (package.Password != null) { //bool success = Removed for simplicity's sake. bool success = true; if (success) { alert.Message = "Success!"; } else { alert.Message = "Failed to register"; } } else { alert.Message = "You need to enter a password!"; } return Json(alert, "text/plain"); } </code></pre> <p>As I said, when the content type is defined as text/plain the browser shows only the response and when it's not defined it prompts the user to download the json-response instead.</p> <p>With FF I seem to get an error about: </p> <pre><code>"event is not defined event.preventDefault(); " </code></pre> <p>This could have something to do with the error.. but I need to prevent the form from posting normally. Is this done differently in FF or IE?</p> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload