JQuery和Ajax - 陷入困境

laz*_*wer 2 asp.net ajax jquery web-services

我已经阅读了网上关于使用JQuery发布ajax的几个教程,所有这些教程都引用了来自Web服务的响应对象作为响应/响应.这让我相信这是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);
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

但是代码在Chrome的Javascript控制台中返回"Uncaught ReferenceError:response not defined".我做了什么假设,我需要重新评估.

chp*_*ipr 6

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

success: function(response) {
    alert(response.d);
}
Run Code Online (Sandbox Code Playgroud)