我有这个功能,发送数据到一个PHP文件,但由于某种原因,它似乎是PHP文件没有得到的数据,jQuery的发送给它。检索信息发送到php文件与jQuery .get
这里是jQuery代码:
<script type="text/javascript" src="JS/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(".hide").hide();
$("#cake").hide();
var boz = $('#cake').val();
var search = $('#search').val();
$.get("petition_send.php", { id: boz, q: search }, function(data){
alert("Data Loaded: " + data);
});
$('.show').click(function checkPass(){
$(".hide").slideDown();
});
});
</script>
现在,这里是php文件:
<?php
$xmlDoc = new DOMDocument();
include_once("petitionhint.php");
$xmlDoc->loadXML($xmlout);
$x=$xmlDoc->getElementsByTagName('friend');
//Get the q parameter from URL
$q = $_GET["q"];
$id = $_GET["petition_ID"];
//Lookup all links from the xml file if length of q>0
if(strlen($q)>0)
{
$hint = "";
for($i=0; $i<($x->length); $i++)
{
$y=$x->item($i)->getElementsByTagName('name');
$z=$x->item($i)->getElementsByTagName('url');
$w=$x->item($i)->getElementsByTagName('photo');
$l=$x->item($i)->getElementsByTagName('location');
if ($y->item(0)->nodeType==1)
{
//Find a link matching the search text
if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
{
if($hint != ""){
$hint .= "<br />";
}
$hint .= "<h1 id='poli'><a id='blue' href='";
$hint .= $z->item(0)->childNodes->item(0)->nodeValue;
$hint .= "&petition_ID='$id' >";
$hint .= $y->item(0)->childNodes->item(0)->nodeValue;
$hint .= "</a> <br /><a id='green'>";
$hint .= $l->item(0)->childNodes->item(0)->nodeValue;
$hint .= "</a>";
$hint .= "<br/><img width='30' height='30' id='schmidt' src='features/";
$hint .= $w->item(0)->childNodes->item(0)->nodeValue;
$hint .= "' /></h1>";
}
}
}
}
// Set output to "no suggestion" if no hint were found
// or to the correct values
if($hint == "")
{
$response = "No suggestions";
} else
{
$response = $hint;
}
//output the response
echo $response;
?>
当我尝试在包括 “$ ID” 变量到PHP代码的一部分这里:
$hint .= "&petition_ID=$id' >";
它没有出现。 $ id变量没有出现。
您可以随时在您的PHP代码中添加一个'var_dump($ _ GET);',然后查看Firebug中的返回数据。 – JAL 2010-11-14 19:45:54