2011-07-25 47 views
0

當我在symfony 1.4中使用ajax時,我有一個很奇怪的問題。我使用Jobeet的例子(18日),但它不工作問題與使用symfony 1.4的ajax

這是我indexSuccess.php的

<script type="text/javascript" > 

$(document).ready(function(){ 

$('#buscador').keyup(function(key) 
{ 
     if (this.value.length >= 3 || this.value == '') 
     { 
      $('#per').load($(this).parents('form').attr('action'), 
         { query: this.value + '*' }); 
     } 
    }); 
}); 
</script> 

<h1>Lista de personas</h1> 

<p>Busque o cree registros de personas en el sistema (Estudiantes, funcionarios, docentes).</p> 

<form action="<?php echo url_for('personas/index')?>"> 
<table> 
    <tr> 
     <td><input type="text" name="buscar" id="buscador"/></td> 
     <td><a href="<?php echo url_for('personas/index')?>"><img src="/images/iconos/Search.png"/></a></td> 
    </tr> 
</table> 
</form> 
<p style="font-size: 11px;color: gray;">Digite un nombre, apellido o número de identificación para buscar</p> 

<div class="per" id="per"> 
<?php echo include_partial('personas/buscaPersonas',array('personass'=>$personass)); ?> 
</div> 

jQuery的腳本檢測輸入的字符,當我寫3個或更多字符它應該加載id ='per'的div。這裏是我的personasAction.class.php

public function executeIndex(sfWebRequest $request) 
{ 

$this->personass = array(); 

if($request->isXmlHttpRequest()) 
     {  
      $this->personass = $this->getRoute()->getObjects(); 
      return $this->renderPartial('personas/buscaPersonas', array('personass'=> $personass)); 
     } 
} 

當我加載頁面我不想看到任何結果。所以,當我做一個ajax調用時,我應該重新加載部分「_buscaPersonas.php」所有結果(僅用於嘗試),但我加載_form.php部分。

這是我的部分:

<table> 
<?php foreach($personass as $personas): ?> 
<tr> 
<td colspan="5" class="tituloTD"><?php echo $personas->getNombre(); ?></td> 
</tr> 
<tr> 
<th>Numero identificación: </th><td><?php echo $personas->getNumeroid() ?></td> 
<th>Email: </th><td><?php echo $personas->getEmail(); ?></td> 
<td><a href="<?php echo url_for('personas/edit?id='.$personas->getId()) ?>"> <img src="/images/iconos/editar.png"/></a></td> 
    </tr> 
     <?php endforeach; ?> 
    </table> 

我一直試圖找到問題出在哪裏,但我不明白這一點。當我使用按鈕進行正常搜索時,它的工作原理是,加載正確的部分,但白衣阿賈克斯加載其他部分。

請有人知道我的錯誤是什麼。

感謝

回答

0

我認爲這是由於您的負載AJAX功能的路徑:

 $('#per').load($(this).parents('form').attr('action'), 
        { query: this.value + '*' }); 

$(本)。家長( '形式')ATTR( '行動')肯定是一個錯誤的價值。 試試這個:
url_for('personas/index')

+0

我試過改變了,但沒有奏效。你是一個負載Ajax,我試圖渲染其他部分總是與同樣的結果。 – diegochk

0

最後我找到了錯誤。我不知道發生了什麼,但如果我發送數據與負載函數,我有錯誤。所以我不得不使用網址發送數據,並且是有效的:)

if (this.value.length >= 3 || this.value == '') 
{ 
    $('#per').load("<?php echo url_for('personas/index')?>"+"?query="+this.value); 
}