Jump to content

XMLHTTP.responseText return whole html


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 post
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 post
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 post
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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...