$ .ajax返回页面的HTML而不是结果

我写了一个简单的web方法,我在客户端调用它来检查数据库中是否存在文本更改的值。 它在本地工作正常,但当我将它移动到我们的开发环境时,它返回响应中页面的整个HTML。 我注意到的唯一的事情是本地Response.Server是IIS7.5,但在我们的Dev服务器上它是IIS6。

这是我的代码:

服务器代码

[ScriptMethod] [System.Web.Services.WebMethod] public static bool CheckInvoiceExists(string vendorNumber, string invoiceNumber) { try { return RequestEntry.CheckInvoiceExists(vendorNumber, invoiceNumber); } catch (Exception exp) { EventLogging.LogError("Error checking if invoice exists: " + exp.Message); return false; } } 

客户代码

 function CheckInvoiceExists() { //var vendNo = $('#VendNoInputDisplay').text(); var vendNo = $('#VendorNumber').val(); var invNo = $('#InvNoInput').val(); var error; $.ajax({ type: "POST", aSync: false, url: "PaymentRequest.aspx/CheckInvoiceExists", data: JSON.stringify({ vendorNumber: vendNo, invoiceNumber: invNo }), contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { if (data.d) { $('#ErrorList').text(GetErrorText("invoiceNumberExists")); $('#InvNoInput').focus().select(); $('#InvNoInput').addClass('error invExists'); } else { $('#InvNoInput').removeClass('error invExists'); ClearErrors(); } }, error: function (jqXHR, textStatus, errorThrown) { $('#ErrorList').text(errorThrown); } }); 

}

这是我本地机器的响应头:

 HTTP/1.1 200 OK Cache-Control: private, max-age=0 Content-Type: application/json; charset=utf-8 Server: Microsoft-IIS/7.5 Access-Control-Allow-Origin: * Persistent-Auth: true X-Powered-By: ASP.NET Date: Mon, 26 Jan 2015 18:18:36 GMT Content-Length: 11 

来自Dev:

 HTTP/1.1 200 OK Connection: Keep-Alive Content-Length: 25586 Date: Mon, 26 Jan 2015 18:30:40 GMT Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET Cache-Control: private 

当我调试它时,它转到$ .ajax调用的错误函数。

 errorThrown : SyntaxError: Unexpected token < jzXHR.responseText : [HTML of the page] textStatus: "parserror" 

当我打开运行CheckInvoiceExist包时,我看到:

 Response is the current page. The request payload is something like this {"vendorNumber":"0007000005","invoiceNumber":"Test1-12"} 

@edit我尝试在我的web方法上面添加以下行,但它没有什么区别

 [System.ServiceModel.Web.WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, UriTemplate = "json")] 

@edit我尝试使用PageMethods而不是使用$ .aJax调用。 然后我尝试了以下测试:

 function Test(response) { alert(response); } PageMethods.CheckInvoiceExists("0007000005","Test1-12",Test); 

在警报消息中,我再次获得了页面的HTML …

好吧,在我的头撞到我的桌子上一整天之后,我终于弄明白了什么是错的。

我的网络配置中的中缺少以下密钥

    

我想IIS7.5并不关心该行是否存在,但是IIS6需要在那里使用该行才能使Web方法正常运行。

谢谢大家的帮助!

更改服务器方法以返回JSON:

 [ScriptMethod(ResponseFormat = ResponseFormat.Json)] public static bool CheckInvoiceExists(string vendorNumber, string invoiceNumber) { try { return RequestEntry.CheckInvoiceExists(vendorNumber, invoiceNumber); } catch (Exception exp) { EventLogging.LogError("Error checking if invoice exists: " + exp.Message); return false; } }