本文介绍了如何将bool从MSFT-MVC动作返回到jQuery $ .ajax()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jQuery调用MSFT-MVC操作$ .ajax()
I am calling a MSFT-MVC action using jQuery $.ajax()
public bool SetActivePatient(string patientID)
{
返回布尔值。
$ .ajax()调用总是触发错误选项。
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');
}
});
调用MVC操作并正常工作,返回True作为.NET bool。查看FireBug,MVC操作的响应是真实的。我是否有错误的dataType?
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?
推荐答案
将您的错误签名更改为:
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.
};
这篇关于如何将bool从MSFT-MVC动作返回到jQuery $ .ajax()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!