I have tried to use the following code to retrieve the data from the webserver (test.asmx.cs) but somehow this is always throw the error to me... does anyone know what is it going wrong?
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";
}
}
}
And the following jquery code have placed under 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");
}
});
});
