1

I used ajax for sending request to server but it not get any response from php page. I am confused what is wrong in my code?

My Index.php page is:-

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        echo 'hello';
        ?>
    </body>
</html>

My html page is:-

    function showHint()
{

var xmlhttp;

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("name").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","index.php",true);
xmlhttp.send();
}
    </script>


</head>
<body>
<input type="text" name="name" id="name" />
<input type="button" name="submit" value="Correct the Address" id="submit" onclick="showHint()"/>

</body>
</html>

What is wrong in my above code?please suggest me some solution?

4
  • Show what you return from index.php Commented May 8, 2014 at 5:54
  • Also you are returning from showHint before going to Ajax. Try removing it. Commented May 8, 2014 at 6:05
  • I suggest using jQuery for Ajax requests if possible. Commented May 8, 2014 at 6:11
  • i am just want to return 'hello' from index.php and make it value of textbox by using innerhtml. Commented May 8, 2014 at 6:14

1 Answer 1

1

You have syntax error showHint() so just check it

<input type="button" name="submit" value="Correct the Address" id="submit" onclick="showHint()"/></td>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.