...

View Full Version : XMLHttpResponse return all page html from php



umen242
01-20-2009, 09:06 PM
Hello all
im trying to invoke js code that submit paramter to php page , but the result
that the XMLHttpRequest Object captures is all the html of the page + the result from the php , what im doing wrong here ?
here is my code :


var rqo;
function setReq(v) {

if (v != "") {
document.getElementById("result").innerHTML = "Fetching " + v;
rqo = new XMLHttpRequest();
var qs = encodeURIComponent(v);
var qry = "index.php?_data_input=" + qs;
rqo.open('GET',qry,true);
rqo.onreadystatechange = handleHttpResponse;
rqo.send(null);
return false;
}
}
function handleHttpResponse() {
var results = "";
qq (rqo.readyState == 4) {
results = rqo.responseText;
document.getElementById("result").innerHTML = results;
}

}
.....
....
<div class="c3" id="result">
&nbsp;
</div>
....
<form method="get" name="_main_form" >
<input type="text"size="50" name="_data_input" id="_data_input">
<input type="button" value="Get Item" onclick="aboutlang(document._main_form._data_input.value)">
</form>
.....

itsallkizza
01-20-2009, 09:10 PM
It'd be nice to see your php api, but I'm going to guess that you're printing out entire html page (and so that's what you should expect to receive in return).

Post your index.php code.

umen242
01-20-2009, 09:57 PM
<?php
if(isset($_GET["_data_input"]))
{

$user_text_input = trim($_GET['_data_input']);
print "<br> this is mt response "<br>

}
else
{
print "_data_input is empty";
}
?>

this is all of the php file i mean the php section

itsallkizza
01-20-2009, 10:23 PM
So the code you just posted is the only code in index.php?


If so then your responseText should include either

"<br> this is mt response"

or
"_data_input is empty"

umen242
01-21-2009, 09:22 AM
yes this is all my code and i dont understand why the response returns me
again all the php page ( html and all the stuff )
here is the full php page :


if(isset($_GET["_data_input"]))
{
print "<br> dddddddd </br>";
}
else
{
print "_data_input is empty";
}
?>
<html>
<style type="text/css">
<!--
.c1 {
clear:both;text-align:center;
}
.c2 {
float:left;width:25%;display:table-cell;vertical-align: middle;
}
.c3 {
float:left;width:74%;border-left:1px solid #000000;display:table-cell;vertical-align: middle;
}
.c4 {
border-top:1px solid #000000;clear:both;
}
.c5 {
border:1px solid #000000;
}
#logo{padding-top:15px;}
-->
</style>

<head>
<script type=text/javascript language=javascript>
<!-- Hide Javascript on old browsers
var rqo;
function aboutlang(v) {
if (v != "") {
document.getElementById("result").innerHTML = "Fetching " + v;
rqo = new XMLHttpRequest();
var qs = encodeURIComponent(v);
var qry = "index.php?_data_input=" + qs;
rqo.open('GET',qry,true);
rqo.onreadystatechange = handleHttpResponse;
rqo.send(null);
return false;
}
}
function handleHttpResponse() {
var results = "";
if (rqo.readyState == 4) {
results = rqo.responseText;
document.getElementById("result").innerHTML = results;
}

}
-->
</script>
</head>
<!-- Specific adjustments for IE -->
<!--[if IE]>
<style type="text/css">
#logo{padding-top:5px;}
</style>
<![endif]-->
</head>
<body>
<div class="c5">
<div class="c1">
<div class="c2"></div>
<div class="c3">
<h1>
<form method="get" name="_main_form" >
<input type="text"size="50" name="_data_input" id="_data_input">
<input type="button" value="Get Item" onclick="aboutlang(document._main_form._data_input.value)">
</form>
</h1>
</div>
</div>
<div class="c4">
<div class="c2">&nbsp;</div>
<div class="c3" id="result">
&nbsp;

</div>
</div>
<div class="c1"><!-- --></div>
</div>

</body>
</html>



im running under apache 2.2 and php5 winxp

itsallkizza
01-21-2009, 03:58 PM
Ok, the responseText is supposed to return the entire requested page's output.

You should place that php code in a separate file (it's more modular anyway).

umen242
01-21-2009, 10:41 PM
Thanks it is right and it is working , now i have another problem
and i don't what to open thread , im reading the manual and seeing the examples
but i still cant find why this regexp doesn't work


$sMatchResult = '/dddd/';
preg_replace('/\//','',$sMatchResult);

the $sMatchResult return still the string with the "/" why ? i like to clean them from the string .

A1ien51
01-22-2009, 06:48 AM
Shouldn't it be

preg_replace('/\//g','',$sMatchResult);

Eric

itsallkizza
01-22-2009, 08:22 AM
Aye you need the global parameter to catch all the slashes.

umen242
01-22-2009, 12:28 PM
no it is still not working ....
:/



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum