Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery $.post error when called from Bootstrap Modal
    primarykey
    data
    text
    <p>In a web app I am developing I display a Modal dialog using Bootstrap. Within that dialog I have form elements and a save button. When the user clicks save I fire a function which calls $.post to invoke an asp.net mvc action to save the data entered.</p> <p>The browser (Chrome) displays the following message when I click the Save button:</p> <blockquote> <p>"Something Unexpected Happened :(....." . </p> </blockquote> <p>After confirming the error message the asp.net action is invoked and the rest of the script completes fine. I also see the same error if I use $.ajax. </p> <p>IE gives slightly different behaviour. Isee the same message in IE but it appears after the success callback function completes.</p> <p>If I call the save function from outside the modal dialog I do not see this error message. </p> <pre><code>function saveUser() { var userId = $('#userId').val(); var fullName = $('#fullName').val(); var userName = $('#userName').val(); var isAdmin = $('#isAdmin').is(':checked'); var authenticationMode = $('#userAuthenticationMode').val(); $.post( "@Url.Action("Save", "Account")", { userId : userId, fullName : fullName, userName : userName, isAdmin : isAdmin, authenticationMode : authenticationMode }, function (data) { if (data.Success) { alert("success"); } else { alert("failed"); } } ); </code></pre> <p>Here is the modal declaration:</p> <pre><code>&lt;div id="update_user_modal" class="modal hide"&gt; . . . &lt;div style="float:right"&gt; &lt;button id="SaveUser" class="btn btn-primary"&gt;Save changes&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>Update:</strong></p> <p>Found the source of the alert message. There's an ajax error handler in the code which a colleague failed to mention:</p> <pre><code>// Set up AJAX error handling ... $(document).ajaxError(function (event, jqXHR, ajaxSettings, thrownError) { if (jqXHR.status == 404) { $("#NotFoundInfoDialog").dialog("open"); } else if (jqXHR.status == 500) { $("#InternalServerErrorDialog").dialog("open"); } else { alert("Something unexpected happend :( ..."); } }); </code></pre> <p>Any ideas on how I can debug the ajax error. jqXHR.status returns 0. </p> <p><strong>Update</strong> When I use $.ajax to make an ajax call the following occurs: <br> First time I attempt to save an unknown ajax exception is raised and the modal closes. <br> If I display the modal again and attempt to Save it works fine. <br> If I know try to display the modal again and save I get an 'Internal Server error'. My mvc action is working fine. </p> <p><strong>Update</strong> Have no idea why but removing the form tags in the modal div solved the problem.</p> <p>Thanks,</p> <p>Lance</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