Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post May 02, 2012 02:45 AM by bruce (sqlwork.com)
Member
419 Points
524 Posts
May 01, 2012 07:29 PM|LINK
Hello, I have an ajax call that will return a boolean. But I found that it is not true, it returned a string. Please see what is wrong.
function ValidateUserName() { $.ajax({ type: "POST", url: "../myWebService.asmx/ValidateUserName", data: "{'sname': '" + $("#<%=TextUserName.ClientID%>").val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", async: false, success: function (data) { return data.d; } }); } function ValidateUserNameSubmitting() { var isValid = ValidateUserName(); return isValid; // found it is undefined. }
Thanks
618 Points
152 Posts
May 01, 2012 07:41 PM|LINK
Is the web service returning a string or is it returning 'undefined' because there was an error?
Add an error handler to your ajax call:
$.ajax({ type: "POST", url: "../myWebService.asmx/ValidateUserName", data: "{'sname': '" + $("#<%=TextUserName.ClientID%>").val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", async: false, error: AjaxError, success: function (data) { return data.d; } }); AjaxError = function (jqXHR, textStatus, errorThrown) { alert(textStatus); alert(errorThrown); }
May 01, 2012 07:55 PM|LINK
The web service returned a bool value. I used the code but no exception.
function ValidateUserName() { $.ajax({ type: "POST", url: "../UserNameWebService.asmx/ValidateUserName", data: "{'strUsername': '" + $("#<%=TextUserName.ClientID%>").val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", async: false, success: function (data) { return data.d; }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); }
All-Star
37594 Points
5573 Posts
May 02, 2012 02:45 AM|LINK
use fiddler to see the response from the server, and check if its valid json.
zhshqzyc
Member
419 Points
524 Posts
json convert?
May 01, 2012 07:29 PM|LINK
Hello, I have an ajax call that will return a boolean. But I found that it is not true, it returned a string. Please see what is wrong.
function ValidateUserName() { $.ajax({ type: "POST", url: "../myWebService.asmx/ValidateUserName", data: "{'sname': '" + $("#<%=TextUserName.ClientID%>").val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", async: false, success: function (data) { return data.d; } }); } function ValidateUserNameSubmitting() { var isValid = ValidateUserName(); return isValid; // found it is undefined. }Thanks
Specs
Member
618 Points
152 Posts
Re: json convert?
May 01, 2012 07:41 PM|LINK
Is the web service returning a string or is it returning 'undefined' because there was an error?
Add an error handler to your ajax call:
$.ajax({ type: "POST", url: "../myWebService.asmx/ValidateUserName", data: "{'sname': '" + $("#<%=TextUserName.ClientID%>").val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", async: false, error: AjaxError, success: function (data) { return data.d; } }); AjaxError = function (jqXHR, textStatus, errorThrown) { alert(textStatus); alert(errorThrown); }zhshqzyc
Member
419 Points
524 Posts
Re: json convert?
May 01, 2012 07:55 PM|LINK
The web service returned a bool value. I used the code but no exception.
function ValidateUserName() { $.ajax({ type: "POST", url: "../UserNameWebService.asmx/ValidateUserName", data: "{'strUsername': '" + $("#<%=TextUserName.ClientID%>").val() + "'}", contentType: "application/json; charset=utf-8", dataType: "json", async: false, success: function (data) { return data.d; }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); }bruce (sqlwo...
All-Star
37594 Points
5573 Posts
Re: json convert?
May 02, 2012 02:45 AM|LINK
use fiddler to see the response from the server, and check if its valid json.