Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从webmethod捕获json中的返回值?_C#_Asp.net_Json_Jquery - Fatal编程技术网

C# 如何从webmethod捕获json中的返回值?

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

Net和Webmethods来使用JSON

我的webmethod返回值如下所示

    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;