jqueryajax在从ashx处理程序获取返回值时遇到问题

jqueryajax在从ashx处理程序获取返回值时遇到问题,jquery,asp.net,ajax,ashx,Jquery,Asp.net,Ajax,Ashx,您好 无论我做什么,我都无法让jqueryajax代码从ashx处理程序页面获得除null以外的响应 这是我的hmt页面: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>:: ashx tester ::</title&

您好

无论我做什么,我都无法让jqueryajax代码从ashx处理程序页面获得除null以外的响应

这是我的hmt页面:

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>:: ashx tester ::</title>
    <link rel="stylesheet" href="js/jqueryui/1.8.6/themes/sunny/jquery-ui.css"
        type="text/css" media="all" />
    <script type="text/javascript" src="js/jquery/1.4.3/jquery.min.js"></script>
    <script type="text/javascript" src="js/jqueryui/1.8.6/jquery-ui.min.js"></script>
    <script type="text/javascript" src="js/json2/0.0.0/json2.js"></script>
    <script type="text/javascript">
        $(function () {
            $('#btnSubmit').click(
                function () {
                    DoIt();
                }
            );
        });

        function DoIt() {
            $('#btnSubmit').hide();
            $.ajax({
                type: "POST",                
                url: "http://localhost:49424/Handler1.ashx",
                data: {
                    firstName: 'Bob',
                    lastName: 'Mahoney'
                },
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function (response) {
                    alert('success: ' + response);
                    $('#btnSubmit').show();
                },
                error: function (response) {
                    alert('error: ' + response);
                    $('#btnSubmit').show();
                }
            });
        }
    </script>
</head>
<body>
    <input id="btnSubmit" type="button" value="Submit" />
</body>
</html>
有什么线索吗

谢谢

戴夫

试试看 url:“/Handler1.ashx”

而不是

 url: "http://localhost:49424/Handler1.ashx",

我只对处理程序使用文本数据类型

      var webServiceURL = 'http://localhost:12400/Handler1.ashx';
        var data = "Key:Value";

        alert(data);

        $("input[id='btnSubmitLead']").click(function () {
            $.ajax({
                type: "POST",
                url: webServiceURL,
                data: data,
                dataType: "text",
                success: function (results) {
                    alert("Your information has been sent to the dealer, thank you");
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(textStatus +"-"+ errorThrown);
                    alert("Your information has not been sent");
                }
            });
        });
所以,我在所有浏览器中都会向处理程序获取信息,但我没有得到正确的确认,因为这总是一个错误。我正在使用html页面提交ajax调用。我还删除了:

         context.Response.ContentType = "application/json"

我的处理程序增加了服务器端的工作量,但对服务器的调用也很好。。。它的回归给了我很多问题。

这个简化的代码对我来说很有用

    $.ajax({
        type: "POST",
        url: "AddProviderToCall.ashx",
        data: {ProviderID: strProviderID, PhyUserID: PhyUserID },
        success: function (response) {
            alert('success: ' + response);
        },
    });
在我的C#handler

{
    context.Response.ContentType = "text/plain";
    context.Response.Write(result);
}

好啊这是奇怪的部分。这起作用了,但不是真的。我需要该页面能够远程调用我的ashx处理程序。但为了测试,我将页面复制到我的项目中,并进行了您建议的更改。成功了!然后我再次尝试远程页面,但这次是在IE中。。。我一直在使用chrome测试远程页面。事实证明,远程页面ajax调用在IE中有效,但在chrome或firefox中不起作用!
{
    context.Response.ContentType = "text/plain";
    context.Response.Write(result);
}