$ .ajax ReferenceError:未定义数据

时间:2014-04-15 19:42:52

标签: javascript jquery html ajax

我正在

  

ReferenceError:未定义数据   和

>NetworkError: 500 Internal Server Error - http://localhost/WebApplication2/js/test.aspx"

但是我的aspx页面位于正确的目录中

我做了所有这些以消除内部服务器错误:

http://pcsupport.about.com/od/findbyerrormessage/a/500servererror.htm

代码按照教程

Index.html(回调数据将在此处发布)

<body>
    <input id="button" type="submit" value="Go" />
    <div id="feedback">    </div>


</body>


这是我的Ajax方法:

$('#button').click(function () {
    $.ajax({
        type: "POST",
        url: "test.aspx",
        data: {"name=" + name},
        success: function (data) {
            $("#feedback").html(data);
        }
    });
});

Test.aspx文件

<form id="form1" runat="server">
<div>
<%Response.Write(Request.Form["name"].ToString()); %>
</div>
</form>

类似帖子:

ajax and “Uncaught ReferenceError: data is not defined”
$.ajax() and "Uncaught ReferenceError: data is not defined"
Ajax data - Uncaught ReferenceError: date is not defined

编辑:JSLint / JSHint / SharpLinter对检测语法错误仍然没什么帮助。我需要一些语法检查的建议

也存在放置数据类型参数的问题..它不在我的情况下。

我无法在那里找到简单的东西......请建议

3 个答案:

答案 0 :(得分:3)

我想,您应该将数据传递为:

data: {name: name},

此外,尝试在成功函数中使用其他变量而不是data

success: function (response) {
   $("#feedback").html(response);
}

答案 1 :(得分:1)

确定..最终让它正常工作......错误是在数据参数(在url之后)

而不是(这是教程代码)

data: {"name=" + name1},

这对我有用

data : {'name':name1},

这是工作代码:

脚本

$('#button').click(function () {
var name1="aa";
    $.ajax({
        type: "POST",
        url: "test.aspx",
        data : {'name':name1},
        statusCode: {
            404: function () { $("#messege").text("Page not found"); },
            500: function () { $("#messege").text("internal server error"); }
        },
        success: function (data) {
            $("#messege").html(data); 
        } });
});

休息是一样的.Below链接是相关且有用的

jquery POST data in aspx page

答案 2 :(得分:0)

就我而言,我以Bootstrap Modal形式加载响应,但未在视图中声明它。