2013-03-26 81 views
0

网和webMethods使用JSON如何从webmethod中捕获json的返回值?

我的WebMethod返回值作为

return ResultValue; 
     // which gives 1 as Return Value on SUcessfull insertion 

如果返回值是1,我希望它在我的JQuery显示为成功

该如何应我赶上在我的webmethod中的返回值?

回答

0

试试这个在您的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' 
}); 

问候

0
$.ajax({ 
    url: 'mypage.html', 
    success: function(data){ 
    if(data ==1) 
     alert('success'); 
    else 
     alert('failure'); 
    }, 
    error: function(){ 
    alert('failure'); 
    } 
}); 

http://api.jquery.com/jQuery.ajax/

,或者您为您的Response对象的状态代码在你的WebMethod。像这样:

Response.Clear(); 
Response.StatusCode = 500; // or whatever code is appropriate 
Response.End;