2013-03-26 40 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;