[英]Retrieve info sent to php file with jquery .get
我有将此功能发送到php文件的功能,但由于某种原因,似乎php文件没有获取jquery发送给它的数据。
这是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变量不会出现。
您正在发送参数id
( boz
)和q
( search
),但正在读取参数q
和petition_ID
。
您没有从$ _GET中选择适当的元素:
$id = $_GET["petition_ID"];
至
$id = $_GET["id"];
和
$hint .= "&petition_ID='$id' >";
至
$hint .= "&petition_ID=$id' >";
也尝试在jQuery调用
$.get("petition_send.php", { "id": boz, "q": search }, function(data){
alert("Data Loaded: " + data);
或考虑将“ id”更改为其他名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.