C# 如何从webmethod捕获json中的返回值?
Net和Webmethods来使用JSON 我的webmethod返回值如下所示C# 如何从webmethod捕获json中的返回值?,c#,asp.net,json,jquery,C#,Asp.net,Json,Jquery,Net和Webmethods来使用JSON 我的webmethod返回值如下所示 return ResultValue; // which gives 1 as Return Value on SUcessfull insertion 如果返回值为1,我希望它在JQuery中显示为success 为此,我应该如何捕获webmethod中的返回值???在您的ajax代码中尝试以下方法: $.ajax({ type: "POST", success: funct
return ResultValue;
// which gives 1 as Return Value on SUcessfull insertion
如果返回值为1,我希望它在JQuery中显示为success
为此,我应该如何捕获webmethod中的返回值???在您的ajax代码中尝试以下方法:
$.ajax({
type: "POST",
success: function(data) {
//data=ResultValue
if(data == 1)
{ // Success Stuff }else {//do stuff}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("error: " + XMLHttpRequest.responseText);
},
dataType: 'json'
});
致意
$.ajax({
url: 'mypage.html',
success: function(data){
if(data ==1)
alert('success');
else
alert('failure');
},
error: function(){
alert('failure');
}
});
或者在webmethod中为响应对象设置状态代码。大概是这样的:
Response.Clear();
Response.StatusCode = 500; // or whatever code is appropriate
Response.End;