Friday, 15 August 2014

jquery - How to not return success when data is not valid, or exception is thrown? -


I am using jQuery Ajax, and I have success: function (msg) ... . When I specify when the hit will be: Error: Function (msg) ...

An issue seems to be that I have no way to go back True or false , because I have to return a view. In a normal web app (contrary to MVC), I used to return only true or wrong, then I can see this boolean value and work accordingly.

How can I specify that I want to jump in some cases error: for function (msg) ? For example, when verification is not passed, then I do not want to say that this is a success. Here is my JQuery code:

  function contact dialog (action, controller) {var url = '/' + + action + '/' + controller; $ ("# Contact Dialogue"). Dialog ({autoOpen: true, hide: "fade", show: "bounce", height: $ (window). Light () / 2, width: $ (window). Method () / 2, title: "An email Send ", button: [{Text:" Send ", click: function () {$ .ajax ({url: url, data: $ (" form "). Serialize (), Reference: This, contentType: 'application / Html; charset = utf-8 ', datatype: "html", success: function (msg) {$ (this) .dialog ("off"); sent-response message (' msgSent ');}, error: work } {SendConfirmMessage ('msgNotSent');}}}}}}, {text: "cancel", click: function () {$ (this) .dialog ("close");}}]});  

} and my HTML code which verifies:

   

Take action in your MVC controller:

  var status = new HTTP tags (); If (DataIsInvalid) // Whatever verification you need to do is {status = HttpStatusCode.BadRequest; } // Any other verification new HTTTPTus code result (status);  

If you need to change it back then it does not trigger error in your AJX, either leave status or set Make this the HTTTPTAS code. OK


No comments:

Post a Comment