2010-11-14 69 views
0

我有這個功能,發送數據到一個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 .= "&amp;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 .= "&amp;petition_ID=$id' >"; 

它沒有出現。 $ id變量沒有出現。

+2

您可以隨時在您的PHP代碼中添加一個'var_dump($ _ GET);',然後查看Firebug中的返回數據。 – JAL 2010-11-14 19:45:54

回答

2

您發送的參數idboz)和qsearch),但你正在閱讀的參數qpetition_ID

2

你不從$ _GET選擇適當的元素:

$id  = $_GET["petition_ID"]; 

$id  = $_GET["id"]; 

$hint .= "&amp;petition_ID='$id' >"; 

$hint .= "&amp;petition_ID=$id' >"; 

也嘗試在jQuery的通話

$.get("petition_send.php", { "id": boz, "q": search }, function(data){ 
    alert("Data Loaded: " + data); 

或考慮改變「身份證」到別的東西。

+0

我改變它,但它仍然不工作:( – Lance 2010-11-14 19:48:53

+0

編輯,嘗試它。 – shevski 2010-11-14 19:57:35

+0

謝謝。有效。但由於某種原因,在我的PHP文件,我不能$ $變量出現在錨標記當它包含在提示中時= – Lance 2010-11-14 20:04:56