Mono:如何使用javascript和jquery使用web服务?
对不起,我的英语不好 我创建了一个包含一些aspx页面的网站,例如Default.aspx和一个名为DataService.asmx的web服务。在Default.aspx页面中,我想使用jquery调用web服务。 问题是我不能使用jquery调用web服务 我在ubuntu服务器版本10.04上使用mono 2.4.4 如何使用javascript和jquery使用web服务 请帮帮我,谢谢 使用firebug我看到了Mono:如何使用javascript和jquery使用web服务?,javascript,jquery,web-services,mono,Javascript,Jquery,Web Services,Mono,对不起,我的英语不好 我创建了一个包含一些aspx页面的网站,例如Default.aspx和一个名为DataService.asmx的web服务。在Default.aspx页面中,我想使用jquery调用web服务。 问题是我不能使用jquery调用web服务 我在ubuntu服务器版本10.04上使用mono 2.4.4 如何使用javascript和jquery使用web服务 请帮帮我,谢谢 使用firebug我看到了 Object reference not set to an insta
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]
}
Javascript(Default.aspx)
这是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"); }
});
});
您的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");}
});
});
注意大小写,数据不是日期,以及用逗号分隔成功和错误。目前我认为不可能从ajax调用调用MyService.asmx/MyMethod。500总是被退回的。几周来我一直在寻求一个解决方案,现在我正在用基于服务的服务替换.asmx。在编辑您问题的代码格式时,我注意到字母上的大写(
文档
,就绪
,Ajax
,等等)想知道这是故意的还是在发布代码的过程中出错了?参数的值是多少?下面是javascript代码$(document).ready(function(){$.ajax({type:'POST',url:'DataService.asmx/SayHello',data:“{}”,contentType:“application/json;charset=utf-8”,数据类型:“json”,成功:函数(){alert(“Ok”);},错误:函数(){alert(“error”);}});
$(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"); }
});
});
$ (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");}
});
});