Я пытался использовать следующий код для получения данных с веб-сервера (test.asmx.cs), но почему-то это всегда выдает ошибку ... кто-нибудь знает, что происходит не так?
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");
}
});
});