Asp.net JQuery和Ajax——即将到来

Asp.net JQuery和Ajax——即将到来,asp.net,jquery,ajax,web-services,Asp.net,Jquery,Ajax,Web Services,我已经在网上阅读了一些关于使用JQuery发布ajax的教程,所有这些教程都将web服务中的响应对象引用为response/response.d——这让我相信这是JQuery的响应处理程序的内置对象 代码段: $('.submit').click(function () { var theURL = document.location.hostname + ":" + document.location.port + "/LeadHandler.aspx/hello"; // this

我已经在网上阅读了一些关于使用JQuery发布ajax的教程,所有这些教程都将web服务中的响应对象引用为response/response.d——这让我相信这是JQuery的响应处理程序的内置对象

代码段:

$('.submit').click(function () {
    var theURL = document.location.hostname + ":" + document.location.port + "/LeadHandler.aspx/hello"; // this will change too
    alert(theURL);
    $.ajax({
        type: "POST",
        url: theURL,
        data: "{'NameFirst':'" + $('#txtFirstName').val() + "'}", // again, change this
        contentType: "applications/json; charset=utf-8",
        dataType: "json",
        success: alert("Success: " + response.d), // this will change
        failure: function (response) {
            alert("Failure: " + response.d);
        }
    });
});

但是,代码在Chrome的Javascript控制台中返回“UncaughtReferenceError:未定义响应”。我正在做哪些需要重新评估的假设。

您需要为成功提供一个要执行的功能:

success: function(response) {
    alert(response.d);
}
成功(如失败)需要一个函数来传递响应对象

$('.submit').click(function () {
    var theURL = document.location.hostname + ":" + document.location.port + "/LeadHandler.aspx/hello"; // this will change too
    alert(theURL);
    $.ajax({
        type: "POST",
        url: theURL,
        data: "{'NameFirst':'" + $('#txtFirstName').val() + "'}", // again, change this
        contentType: "applications/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
            alert("Success: " + response.d);
        },
        failure: function (response) {
            alert("Failure: " + response.d);
        }
    });
});
学究式响应为了让它进行验证,用代码回复的需要一个,在成功函数{}的结束括号之后,