Wednesday, May 22, 2024

Jquery ajax - ASP.NET when exception occur in asp.net

 success: function(data) {

  if (typeof data == "string")

    data = JSON.parse(data);

  if (data.success) {

    // Code if success.

  } else {

    // Code if error.

  }

},


and when method not found, than it will gone to error or any function not called by ajax call.

 $.ajax({
    type: "POST",
    data: formData,
    url: "/Forms/GetJobData",
    dataType: 'json',
    contentType: false,
    processData: false,               
    success: function (response) {
        if (response.success) {
            alert(response.responseText);
        } else {
            // DoSomethingElse()
            alert(response.responseText);
        }                          
    },
    error: function (response) { // // Added this event to capture the failed requests.
alert("error!"); // } });


ref:- https://stackoverflow.com/questions/37187699/ajax-error-is-returned-as-success

No comments:

Post a Comment