jquery - how to compare the result of success function of ajax with a string -
$.ajax({ type: "post", url: "test.jsp", data: "user="+name.val(), success: function(msg) { $('#result').hide(); $("#result").html(msg) .fadein("slow"); if( msg =="available") { alert(msg); } } }); test.jsp <h1> <% string user=request.getparameter("user"); if(user.equals("prerna")) out.print("available"); else out.print("not available"); %> </h1>
i want compare value returned success function compared string above code not working want add css class "#result" id. alert box not comming.
something there blank space. $.trim() function can delete blank spaces. works!!!
$.ajax({ type: "get", url: url, success: function(data) { var result = $.trim(data); if(result==="available"){ alert("available"); return false; } } });
Comments
Post a Comment