Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery:-[object Object] error

i have a validation.js file

var name = $("#name");

    $.ajax({
        type:       "get",
        url:        "test.jsp",
        data:           "name="+name,
        success:    function(msg) {

            $('#result').hide();

            $("#result").html(msg)
            .fadeIn("slow");
        }
    });

test.jsp

</head>
    <body>
        <h1><%
        String user=request.getParameter("name");
        out.print(user);
        %></h1>
    </body>

the login user.jsp file

<form method="post" id="customForm" action="welcome.html">
        <div>
            <label for="name">Name</label>
            <input id="name" name="name" type="text" />
                            <span id="nameimage"></span>

            <span id="nameInfo"></span>
                          <p id="result"></p>  
        </div>

i have to show the username in my form as soon as user goes to next feild in my form.but it is showing [object Object] error in place where p tag starts

like image 723
Prerna Avatar asked Feb 07 '11 17:02

Prerna


1 Answers

looks like msg isn't what you expect. I think you want msg.responseText

The reason you see [object Object] is because msg is of type object and you pass it into .html which will convert it to a string. And thus the html is filled with the string representation of object which in this case is "[object Object]"

like image 71
Raynos Avatar answered Oct 05 '22 22:10

Raynos