[英]“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.