Jump to content

XMLHTTP.responseText return whole html


Halim

Recommended Posts

Hi,

 

I need simple help. I just want to retrieve the input value $q that is passed from javascript to php.

But XMLHTTP.responseText return the both input value + whole html ? Please help.

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Singapore Godown</title>

 

 

 

</head>

 

 

<body >

 

<script>

function showHint(str) {

if (str.length==0) {

document.getElementById("txtHint").innerHTML="";

return;

}

var xmlhttp=new XMLHttpRequest();

xmlhttp.onreadystatechange=function() {

if (xmlhttp.readyState==4 && xmlhttp.status==200) {

 

document.getElementById("txtHint").innerHTML=xmlhttp.responseText;

 

}

}

xmlhttp.open("POST","test.php?q="+str,true);

xmlhttp.send();

}

</script>

 

<table>

<input type="text" onkeyup="showHint(this.value)">

<div id="txtHint"></div>

</table>

<?php

 

// get the q parameter from URL

$q=$_REQUEST["q"];

echo "Input: ".$q;

 

 

?>

 

 

</body>

</html>

 

Regards,

Halim

Link to comment
Share on other sites

Your PHP page should be programmed to only print the data that you need. Make a PHP file specifically intended to respond to AJAX requests.

In other words, the file should only have this in it:

<?php// Start of file// get the q parameter from URL$q = $_GET["q"];echo "Input: ".$q;// End of file?> 
Link to comment
Share on other sites

Hi Ingolme,

 

Thanks it works!

 

But i have another question:

 

If i need to retrieve more variables (100 variables) how do I do that ?

 

document.getElementById("txtHint").innerHTML=xmlhttp.responseText;

document.getElementById("txtHint2").innerHTML=xmlhttp.responseText;

document.getElementById("txtHint3").innerHTML=xmlhttp.responseText;

... and so on doesnt seem to work ?

 

Please advise.

 

Thanks

Regards,

Halim

Link to comment
Share on other sites

Retrieve 100 variables from the server?

 

You will need to make a new request for each new page you load from the server. Either that or ask PHP to return all the data at once.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...