抱歉我的英文
我创建了一个包含一些aspx页面的网站,例如Default.aspx,以及一个名为DataService.asmx的Web服务。在Default.aspx页面中,我想使用jquery调用Web服务。 问题是我无法使用jquery
调用Web服务我在ubuntu服务器版本10.04上使用mono 2.4.4。
如何使用javascript和jquery来使用Web服务?
请帮助我,谢谢
使用萤火虫我看到了
Object reference not set to an instance of an object
Description: HTTP 500. Error processing request.
Stack Trace: System.NullReferenceException: Object reference not set to an instance of an object at System.Web.Script.Services.WebServiceData.GetWebServiceData (System.Web.HttpContext context, System.String virtualPath, Boolean failIfNoData, Boolean PageMethods) [0x00000 ] at System.Web.Script.Services.WebServiceData.GetWebServiceData (System.Web.HttpContext context, System.String virtualPath) [0x00000] at System.Web.Script.Services.RestHandler.CreateHandler (System.Web.HttpContext context) [ 0x00000] at System.Web.Script.Services.RestHandlerFactory.GetHandler (System.Web.HttpContext context, RequestType System.String, System.String url, pathTranslated System.String) [0x00000] at System.Web.Script.Services.ScriptHandlerFactory . GetHandler (System.Web.HttpContext context, RequestType System.String, System.String url, pathTranslated System.String) [0x00000] at System.Web.HttpApplication.GetHandler (System.Web.HttpContext context, System.String url, Boolean ignoreContextHandler) [0x00000] at System.Web.HttpApplication.GetHandler (System.Web.HttpContext context, System.String url) [0x00000] + at System.Web.HttpApplication <Pipeline> c__Iterator2.MoveNext () [0x00000]
版本信息:运行时:单声道2.4.4 ASP.NET版本:2.0.50727.1433
网络服务代码(DataService.asmx)
[WebService (Namespace = "http://tempuri.org/")]
[WebServiceBinding (ConformsTo WsiProfiles.BasicProfile1_1 =)]
[ScriptService ()]
public class DataService: System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod (ResponseFormat = ResponseFormat.Json, XmlSerializeString = false)]
public string SayHello ()
{
return "Hello !!!";
}
}
Javascript(Default.aspx)
$ (Document). Ready (function () {
$.Ajax ({
type: "POST",
url: _webServiceAddress + method,
Date: parameters,
contentType: "application / json, charset = utf-8",
dataType: "json",
success: function (data) {alert (data);}
error: function () {alert ("Error");}
});
});
这是JavaScript代码。另一个是错的,对不起
$(document).ready(function () {
$.ajax({
type: "POST",
url: "DataService.asmx/SayHello",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () { alert("Ok"); },
error: function () { alert("Error"); }
});
});
答案 0 :(得分:2)
您的javascript不正确:
$ (document). ready (function () {
$.ajax ({
type: "POST",
url: _webServiceAddress + method,
data: parameters,
contentType: "application/json,charset=utf-8",
dataType: "json",
success: function (data) {alert (data);},
error: function () {alert ("Error");}
});
});
记下大写,数据不是日期,以及逗号分隔成功和错误。
答案 1 :(得分:0)
目前我认为无法从ajax调用调用MyService.asmx / MyMethod。总是返回500。我几周都在寻求解决方案,现在我正在用基于ServiceStack.NET的服务取代.asmx。