Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$.ajax ReferenceError: data is not defined

I am getting

ReferenceError: data is not defined and

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

But my aspx page is in right directory

I did all these to remove internal server error :

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

Code is as per tutorial

Index.html (Callback Data will be posted Here)

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


</body>


this is My Ajax method :

$('#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>

similar Posts :

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

Edit : JSLint /JSHint /SharpLinter still not helping much for detecting syntax Error .I need some suggestion for syntax check

there were issue of placing datatype parameter too.. it is not in my case .

I could not able to find something simple there..Please suggest

like image 566
user3487944 Avatar asked Apr 15 '14 19:04

user3487944


2 Answers

I guess, you should pass data as:

data: {name: name},

Also, instead of data, try to use some other variable in the success function:

success: function (response) {
   $("#feedback").html(response);
}
like image 79
Sahil Mittal Avatar answered Oct 14 '22 23:10

Sahil Mittal


ok ..Finally got it working ... error was in data parameter (after url)

Instead of (this is tutorial Code)

data: {"name=" + name1},

this worked for me

data : {'name':name1},

Here is working Code :

script

$('#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); 
        } });
});

rest is same .Below link was relevant and helpful

jquery POST data in aspx page

like image 27
user3487944 Avatar answered Oct 15 '22 00:10

user3487944