0
我想使用jQuery調用.NET asmx web服務。我一直在使用指南here和here,據我所知我跟着他們去信。使用jQuery調用asmx web服務
服務代碼:
[WebService(Namespace = "http://tempuri.org/", Description = "...")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class MyService : WebService
{
private static readonly IKernel NinjectKernel = new StandardKernel(new IocModule());
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public string HelloWorld(string name)
{
return string.Format("Hello {0}", name);
}
我可以高興地瀏覽到Firefox中的服務,並調用了HelloWorld方法。
客戶端的jQuery:
if (ajaxRunning) {
return;
}
ajaxRunning = true;
var webMethod = "http://localhost:51546/MyService.asmx/HelloWorld";
var inputname = "Jack";
$("[id$='spinner']").show();
$("[id$='spinnerText']").show();
$.ajax({
type: "POST",
url: webMethod,
contentType: "application/json; charset=utf-8",
dataType: "json",
data: {name: inputname},
success: function (msg) {
$("[id$='spinner']").hide();
$("[id$='spinnerText']").hide();
ajaxRunning = false;
alert(msg.d);
},
error: function() {
$("[id$='spinner']").hide();
$("[id$='spinnerText']").hide();
ajaxRunning = false;
alert("Fail");
}
});
當我運行有螢火蟲沒有錯誤,只是失敗警報彈出的JavaScript。請告訴我,我是否做了明顯錯誤的事情?
在此先感謝