Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Simple Ajax doesn't call doesn't return anything from the PHP page! Please help.

    The idea is simple at the moment. I just want the message from PHP to return and be alerted on the client side. Here is the HTML and JS
    Code:
    Enter your email: <input id="email" type="text" />
    <input type="button" onclick="setXMLHttpRequest()" value="Go!" />
    
    <script type='text/javascript'/>
    
    		var http;
    		
    		function setXMLHttpRequest()
    		{
    alert("Alert made!");
    			if(window.XMLHttpRequest)
    				http = new XMLHttpRequest();
    			else if(window.ActiveXObject)
    				http = new ActiveXObject("Microsoft.XMLHTTP");
    				
    				url = "http://convolutedconstruct.com/Ajax/checkemail.php?email=" + document.getElementById('email').value;
    				http.onreadystatechange = display;
    				http.open("GET", url, true);
    				http.send(null);
    			
    		}
    		
    		function display()
    		{
    			if (http.readyState == 4)
    				{	
    					infostr = http.responseText;
    					alert(infostr);
    				}
    		}
    </script>
    According to the alert in the first function, the function is being called.

    Here is the PHP page being called:
    Code:
    <?php
    $email = $_GET['email'];
    $message = "You've made it to the PHP page! Here is the email you sent: ";
    echo $message.$email;
    ?>

    When the JS function display() runs, I get a blank alert box. I am currently editing the HTML and JS in a Wordpress draft. Does that matter? Thanks for any help.
    Last edited by The Noob Coder; 08-04-2012 at 12:14 AM. Reason: Grammar mistake.

  • #2
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    when i run that code
    it echos back whatever
    is in the textbox
    (so it works)
    but
    you should change

    http.onreadystatechange = display;
    http.open("GET", url, true);
    http.send(null);

    to

    http.open("GET", url, true);
    http.onreadystatechange = display;
    http.send(null);

  • Users who have thanked DaveyErwin for this post:

    rashod (08-12-2012)

  • #3
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts
    1) So you're getting a message from the PHP page without making any changes to the code up there? Strange, I wonder I get a blank alert box when I do it. Is there anything I can check or fix to get back something from the PHP page?

    2) What would switching those lines do, if you don't mind explaining?
    Last edited by The Noob Coder; 08-04-2012 at 12:19 AM.

  • #4
    Regular Coder
    Join Date
    Aug 2010
    Posts
    974
    Thanks
    19
    Thanked 212 Times in 210 Posts
    Quote Originally Posted by The Noob Coder View Post
    1) So you're getting a message from the PHP page without making any changes to the code up there? Strange, I wonder I get a blank alert box when I do it. Is there anything I can check or fix to get back something from the PHP page?

    2) What would switching those lines do, if you don't mind explaining?
    yeah , it workrd from
    here (check your logs)

    2) just the way the examples
    you find on the web are written

  • #5
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I see. Where can I find this log?

  • #6
    New Coder The Noob Coder's Avatar
    Join Date
    Jul 2012
    Location
    The City that Never Sleeps
    Posts
    99
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation

    Can anyone help me please? I still get a blank response from the PHP page. The page itself seems to work (http://convolutedconstruct.com/Ajax/checkemail.php) as it displays the text from the echo, but I get nothing back to the JS!
    Last edited by The Noob Coder; 08-05-2012 at 05:12 PM.


  •  

    Tags for this Thread

    Posting Permissions

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