[英]“undefined” result after getting data from web service in asp.net
很抱歉打扰您,但我需要帮助。 我想从asp.net中的Web服务获取数据。 我已经从下一个JQuery调用了该服务:
$(document).ready(function () {
$("#btn").click(function () {
var name = "";
$.ajax({
type: "POST",
contenttype: "application/json; charset=utf-8",
data: "{null}",
url: "EmployeeInfo.asmx/GetEmployeeInfo",
dataTyp: "json",
success: function (res) {
name = res.d;
alert(name);
},
error: function (err) {
alert(err);
}
});
});
});
我将从数据库获得Employee名称,但是下一个代码仅用于测试:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public string GetEmployeeInfo()
{
return "John";
}
问题是从检索到的结果中得到“未定义”。 我错过了什么吗?
谢谢大家的努力和帮助
$(document).ready(function () {
$("#btn").click(function () {
var name = "";
$.ajax({
type: "POST",
url: "*youepage.aspx*/GetEmployeeInfo",
data: "",
contentType: "application/json",
dataType: "json",
success: function (response) {
name = response.d;
alert(name);
},
error: function (response) {
alert(response);
}
});
});
});
测试:在同一页(您的.aspx)中,转到后面的代码并编写:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static string GetEmployeeInfo()
{
return "jack";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.