Bangalore Bangalore - 1 year ago 142
HTML Question

string matching not working in js?

when i tried to check my Ajax response with string then its always printing fail case.

Here is my ajax part

var username = document.getElementById("name").value;
var password = document.getElementById("password").value;
var dataString = 'email='+ username + '&password='+ password;

type: "post",
data: dataString,
success: function(data) {
var test = data.replace(/(\r\n|\n|\r)/gm," ");
alert(test); //working
if(test == "1"){ //condition failed
alert("fail"); //printing this
error: function(xhr, desc, err) {
console.log("Details: " + desc + "\nError:" + err);

alert enter image description here

Answer Source

what I am guessing is that test is a string like "1 ", there are whitespace inside

// instead of data.replace(/(\r\n|\n|\r)/gm," ")

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download