My function 'GetResultById' returns true or false. How can I check the return result from the function in JQuery? I am trying to hide and show RadComboBox depending on the result. Here is my code. Also I would like to hide RadComboBox when the page loaded. I put combo.hideDropDown() in Init function but it doesn't seem to be working. Please let me know.
$.ajax({
url: applicationPath + "/test/Test.svc/GetResultById",
type: "POST",
dataType: "json",
data: '{"sId":' + sender.get_value() + '}',
开发者_Go百科 contentType: "application/json; charset=utf-8",
success: function(result)
{
if(result == true)
{
combo.hideDropdown();
}
}
When using a service in ASP and an AJAX call, I believe the results are always passed back in the "d" property. That is to say your callback on an AJAX success will have the "actual" result in result.d
property, not just result
.
e.g.
success: function(result){
alert(result.d); // actual return result
}
(Or it may be ".d", I honestly forget right now, but either way "result" alone (I don't believe) has the result)
Update
it appears I was right about the logic, not the property. result.d
will have your return result.
I am not sure, but I think the result will not be delivered as a boolian but as a string. therefore you have to check for result == "true"...
If you use any ajax function in asynchronous mode, you will not return a value that calls the function depending of the result of the consultation as the call is asynchronous.
to display and hide something you can use jQuery.ajax events:
beforeSend complete (or "error" and "success")
Documentation of jQuery.ajax
The best is to debug with Firebug. It could very well be that your JSON serialization framework you use on the server, doesn't output the boolean directly, but as a field of an object instead.
精彩评论