【发布时间】:2011-07-22 08:41:41
【问题描述】:
我想从 Ajax 调用中返回多个值。所以我根据这个页面修改了我的代码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)' 返回 {"fullname": "Joe", "success" : "true"}
但是 'alert(data.fullname)' 返回未定义。正确的值应该是 Joe
我错过了什么吗?非常感谢任何建议。
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_GetFullName返回类型有问题。因为如果WebMethod正确,alert(data) 应该提醒object Object。 -
@ChristopheCVB 数据类型为字符串
-
@naveen 你是对的,返回类型是错误的字符串