PDA

View Full Version : neither code in if blocks alerts executes.



lse123
03-27-2013, 05:23 PM
having alert(ajax2.responseText);//== "mobiAppDiv"
neither code in if blocks alerts executes...well???????????????????


ajax2.onreadystatechange=function()
{
if (ajax2.readyState==4 && ajax2.status==200)
alert(ajax2.responseText);//== "mobiAppDiv"
{
if (ajax2.responseText == "mobiAppDiv") {
alert("The "+email+" already existed in Notification List!");
} else if ("mobiAppDivInserted" == ajax2.responseText) {
alert("The "+email+" entered in Notification List!");
}
}
}
ajax2.send();

jscheuer1
03-27-2013, 05:50 PM
The responseText is usually rich HTML. However, if you are getting results from a PHP script, it might be something like what you're looking for. But the == test for equality in javascript demands that there be no differences other than type (string, number, boolean, etc. - and then only if one can be easily type converted to the other's type) in the two things being compared. In the case of two strings (what you have here), if there's a carriage return, line feed, space, tab, none of those will show up here:



alert(ajax2.responseText)

because the alert method at times strips those, in other cases they are preserved, but cannot be easily seen because there's little or no frame of reference. How would you know there's a preceding or trailing white space character in an alert, you can't see it. It may or may not even create an offset of any kind.

So I would suggest that instead of the == comparison, use a regular expression or indexOf method. Using indexOf is probably best for this:


ajax2.onreadystatechange=function()
{
if (ajax2.readyState==4 && ajax2.status==200)
{
alert(ajax2.responseText);//== "mobiAppDiv"
if (ajax2.responseText.indexOf("mobiAppDiv") > -1) {
alert("The "+email+" already existed in Notification List!");
} else if (ajax2.responseText.indexOf("mobiAppDivInserted") > -1) {
alert("The "+email+" entered in Notification List!");
}
}
}
ajax2.send();

Another possibility is that the variable 'email' is undefined. That would also stop the alerts from happening.

It could be something else, something we cannot see from the code snippet you provide.

The browser cache may need to be cleared and/or the page refreshed to see changes.

If you want more help, please include a link to the page on your site that contains the problematic code so we can check it out.

lse123
03-27-2013, 10:28 PM
used .indexOf(" solved thks!

lse123
03-27-2013, 11:21 PM
//alert(ajax2.responseText);
if (ajax2.responseText.indexOf("WmobiAppDivInserted")) {
/**/ document.getElementById("mobiAppDivAlreadyIn").style.display = "none";
document.getElementById("mobiAppDiv").style.display = "none";
document.getElementById("mobiAppDivInserted").style.display = "block";
alert("The "+email+" entered in Notification List!");


} else if (ajax2.responseText.indexOf("mobiAppDivAlreadyIn")) {
/**/ document.getElementById("mobiAppDiv").style.display = "none";
document.getElementById("mobiAppDivInserted").style.display = "none";
document.getElementById("mobiAppDivAlreadyIn").style.display = "block";
alert("The "+email+" already existed in Notification List!");

}

}
}
ajax2.send();


worked but 3nd alert never executes event the first alert(test alert) shows="mobiAppDivAlreadyIn", well?

jscheuer1
03-28-2013, 02:31 AM
Right, I was just thinking that. Reverse the order of the tests. Because "mobiAppDiv" can be found in both "mobiAppDiv" and in "mobiAppDivInserted", you would need to test for "mobiAppDivInserted" first. If it's found, execute the code for that. If it's not found, then test for "mobiAppDiv". Then do whatever depending upon whether or not that's found.

lse123
03-28-2013, 04:31 PM
actually i also mention this and added a "W" in first... see last post ... but the same? any hint ..

lse123
03-28-2013, 09:29 PM
try it

http://www.l-web-dev.net/contains/index.php

press last word here>>>

1st Paragraph >>> To be notified when this App is ready click here!!!