我試圖使用下面的代碼從web服務器(test.asmx.cs)中檢索數據,但不知何故,這總是把錯誤給我...有誰知道它出了什麼問題?無法使用ajax調用web服務器來獲取返回結果.net c#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace Test
{
/// <summary>
/// Summary description for autocomplete
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
// [System.Web.Script.Services.ScriptService]
public class autocomplete : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
[WebMethod]
public static string streetNameSearch(int id)
{
return "Melbourne|North Melbourne|South Melbourne|Richmond|North Richmond";
}
}
}
而下面的jQuery代碼已經把pgTest.aspx
$("#example").keyup(function() {
$.ajax({
type: "POST",
url: "pgTest.aspx/streetNameSearch",
data: '{"id":"' + 1 + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var returnData = data.d;
alert(returnData)
},
error: function (xhr, ajaxOptions, thrownError) {
alert(ajaxOptions);
},
timeout: function (data) {
alert("time out");
}
});
});
正在拋出的錯誤是什麼? – jon3laze 2011-04-06 03:18:04
@ jon3laze:錯誤只是'錯誤', – 2011-04-06 03:24:21
在你的方法streetNameSearch中放置一個斷點並檢查它是否被調用? – 2011-04-06 03:34:56