how to compare response.Text with Some String in ajax
I have a problem, I'm returning data from a servlet to an AJAX function and in this function I want to compare the response.Text
with some String, e.g x, but it does not compare it. I have the following code;
function ajaxhandler()
{
tableHtml=response.Text
if(tableHtml=='true')
alert("Valid Move");
else
alert("invalid move")
}
but this doesnt alert anything.
in my servlet i had done this;
void myfunction(HttpServlet request,HttpServlet response)
{
String user=(session.getAttribute("user"));
if(user=="john")
out.println("true");
else
out.println("false");
}
开发者_JS百科
Please post the result of console.log(JSON.Stringify(response));
. I believe you are not sending a correct JSON response. Try this instead:
JSONObject jsonResponse = new JSONObject();
if(user.equals("john"))
jsonObject.put ("Text", "true");
else
jsonObject.put ("Text", "false");
out.println(jsonObject.toString());
精彩评论