I want to return multiple values from Ajax call. So I modified my codes based on this page Jquery return multiple values in ajax call
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "AJAX_custom_function.aspx/AJAX_GetFullName",
data: '{userid: "' + arguments.Value + '"}',
dataType: "json",
async: false,
success: function (data) {
alert(data);
alert(data.fullname);
},
error: function (httpRequest, textStatus, errorThrown) {
alert("status=" + textStatus + ",error=" + errorThrown);
}
});
'alert(data)' returns {"fullname": "Joe", "success" : "true"}
But 'alert(data.fullname)' returns undefined. The correct value should be Joe
Did I missing something? Any advice is very much appreciated.
AJAX_GetFullName
<System.Web.Services.WebMethod()> _
Public Shared Function AJAX_GetFullName(ByVal userid As String) As Object
Dim isValid As Boolean = False 'by default, user always not exist
Dim strFullName As String = ""
isValid = IsUserIDExist(userid, strFullName)
If isValid Then
Return "{'fullname': '" & strFullName & "', 'success': 'true' }"
Else
Return "{'fullname': '', 'success': 'false' }"
End If
End Function
WebMethodAJAX_GetFullNamethere is something wrong with the return type. because alert(data) should alertobject Objectif theWebMethodis correct.