I got a silly error that I don’t know why is happening.
Basically i get the return from the AJAX code “The table PAGES exists” and I can output that to the <p> tag if I put it after declaring var response = data; but somehow it won’t output anything when is inside the IF statement inside the functionResponse.
Can anyone tell me why? Am I passing the variable wrong?
$(document).ready(function(){
function functionResponse (response){
if (response == "The table PAGES exists"){
$("p").html(response);
}
} // close of functionResponse
$("#iForm").submit( function(event){
event.preventDefault();
var user = $("input[name=username]").val();
var password = $("input[name=password]").val();
var dbName = $("input[name=dbName]").val();
var server = $("input[name=server]").val();
$.get("1.php", {username: user, password: password, dbName: dbName, server: server },function(data){
var response = data;
functionResponse (response);
}) // close of .get
})
})
Since trimming worked at my suggestion I’m entering it as an answer with the following explanation.
the return handler for your get function was able to assign the value to the p tag because assigning doesn’t care about white space, especially assigning html, the browser just ignores all that extra blank space.
It’s not passing it to a function that made it break, it was the string comparison. The browser may not care about white space in the HTML, but JavaScript cares a whole lot about white space when doing a string comparison.
The text
and
will appear the same when the browser renders them, as repeated spaces are ignored. But just by looking at them you can see that they are not the same string. Javascript will not ignore the white space that leads and trails your sting unless you tell it to by trimming it.