views:

465

answers:

1

I am calling a MSFT-MVC action using jQuery $.ajax()

public bool SetActivePatient(string patientID)
{

which returns a boolean.

The $.ajax() call is always firing the error option.

$.ajax({
  type: 'POST',
  url: '/Services/SetActivePatient',
  data: { 'patientID': id },
  dataType: 'text',
  success: function(returnVal) {
  if (returnVal == "True") {
     ...
    }
    else {
      alert('Error setting active patient return value, PatientID=' + id);
    }
  },
  error: function() {
    alert('Error in ajax call');
  }
});

The MVC action is called and works correctly, returning "True" as a .NET bool. Looking in FireBug the response is "True" from the MVC action. Do I have the wrong dataType?

A: 

Change your error signature to:

error:function (xhr, ajaxOptions, thrownError)
{
//inspect xhr.responseText, thrownError variables to find out what is the exact error.
//Once we know the exact error, it could be debugged further. 
};
SolutionYogi
Here's the error information being return xhr {...} onreadystatechange: {???} readyState: 4 responseBody: {...} responseStream: {...} responseText: "True" responseXML: {...} status: 200 statusText: "OK" ajaxOptions "parsererror" thrownError undefined
ChrisP