Results 1 to 7 of 7

Thread: neither code in if blocks alerts executes.

  1. #1
    Join Date
    Jan 2012
    Posts
    74
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default neither code in if blocks alerts executes.

    having alert(ajax2.responseText);//== "mobiAppDiv"
    neither code in if blocks alerts executes...well???????????????????
    Code:
    	
    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();

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,027
    Thanks
    44
    Thanked 3,210 Times in 3,172 Posts
    Blog Entries
    12

    Default

    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:

    Code:
    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:

    Code:
    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Jan 2012
    Posts
    74
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    used .indexOf(" solved thks!

  4. #4
    Join Date
    Jan 2012
    Posts
    74
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    Code:
    			//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?

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,027
    Thanks
    44
    Thanked 3,210 Times in 3,172 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Jan 2012
    Posts
    74
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    actually i also mention this and added a "W" in first... see last post ... but the same? any hint ..

  7. #7
    Join Date
    Jan 2012
    Posts
    74
    Thanks
    10
    Thanked 0 Times in 0 Posts

    Default

    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!!!

Similar Threads

  1. I hope to know if there is an open source code to make like these blocks in this site
    By fahedaw in forum Looking for such a script or service
    Replies: 0
    Last Post: 01-26-2010, 08:03 PM
  2. tooltip and div blocks
    By littleus in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 05-03-2009, 12:16 PM
  3. Alerts
    By wanapitei in forum JavaScript
    Replies: 14
    Last Post: 02-22-2008, 04:51 PM
  4. ajaxtabs "rev" only executes on first load
    By jez777 in forum Dynamic Drive scripts help
    Replies: 7
    Last Post: 08-22-2007, 04:41 PM
  5. monitoring script does not email alerts
    By sonny2 in forum Other
    Replies: 0
    Last Post: 01-27-2006, 10:07 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •