jquery ajax调用适用于localhost,但不适用于实时服务器

我整天都在研究这个问题,这似乎是一个常见的问题,但我找不到解决方案。

我正在使用jquery的$.ajax()函数进行服务调用,以更新数据库中的某些值。 它在localhost上运行正常,但在实际的服务器上,我在控制台窗口中收到500内部服务器错误。

我的客户端代码如下:

 var param = FunctionToMakeKeyValueString(); $.ajax({ type: "POST", url: "../Helpers/Autocomplete.asmx/OrderStatements", data: { param: param }, clientType: "application/json; charset=utf-8", datatype: "json", async: true, success: function () { ShowSuccess();}, error: function () { ShowError(); } }); 

服务器端代码是:

 [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] // 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 { public AutoComplete () { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public void OrderStatements(string param) { IncomeStatementService service = new IncomeStatementService(); string[] comps = param.Split(';'); foreach (string s in comps) { int id; short order; string[] pieces = s.Split(':'); if (int.TryParse(pieces[0], out id) && short.TryParse(pieces[1], out order)) { IncomeStatement statement = service.FindBy(id); statement.Order = order; service.UpdateOrder(statement); } } } } 

实际的asmx文件就是

   

我确定url是正确的(.js文件位于Helpers的兄弟文件夹中,其中包含asmx),但是我还需要在IIS或web.config文件中设置其他内容吗? 谢谢!

@Mike W的评论让我看了一下服务器错误日志,我发现:

 Exception type: InvalidOperationException Exception message: Request format is unrecognized for URL unexpectedly ending in '/OrderStatements'. 

我用谷歌搜索了这个消息让我进入这个堆栈溢出问题 ,似乎就像将它添加到我的配置文件的systen.web部分一样简单:

       

您可以尝试在web.config httpHandlers中添加以下行

      

您在JavaScript / Jquery中提供的主机链接可能存在问题

请记下来如果您正在查看chrome清除浏览器数据,您将在两端看到相同的结果