好的,所以我创建了一个测试项目,只是为了验证jQuery AJAX是否可以与asp.net服务一起使用,并且没有问题。我使用了在VS
Studio中创建的默认HelloWorld服务。我通过jQuery这样调用服务:
在Default.aspx中:
$(document).ready(function() {
//test web service
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "TestService.asmx/HelloWorld",
data: "{}",
dataType: "json",
success: function(msg) { alert(msg);},
error: function (XMLHttpRequest, textStatus, errorThrown) {
debugger;
}
});
});
在TestService.asmx中
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
namespace WebServiceTestWitJQuery
{
///
/// Summary description for TestService
///
[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 TestService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
}
然后,我继续进行操作,并完全复制了项目中的所有内容,但它不起作用。我收到500个服务器错误。
我验证了以下内容:
还有什么?