0

symfony 1.4 で ajax を使用すると、非常に奇妙な問題が発生します。jobeet の例 (18 日目) を使用しましたが、機能しません。

これは私の 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>

問題がどこにあるかを見つけようとしましたが、わかりません。通常の検索にボタンを使用すると、正しいパーシャルをロードしますが、他のパーシャルをロードします。

誰かが私のエラーを知ってください。

ありがとう

4

2 に答える 2

0

これは、load ajax 関数のパスによるものだと思います。

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

$(this).parents('form').attr('action') は確かに間違った値です。これを試してください:
url_for('personas/index')

于 2011-07-26T10:27:21.590 に答える
0

最後に、エラーを見つけます。何が起こるかわかりませんが、ロード機能でデータを送信するとエラーになります。したがって、URLを使用してデータを送信する必要がありましたが、うまくいきました:)

 if (this.value.length >= 3 || this.value == '')
 { 
   $('#per').load( "<?php echo   url_for('personas/index')?>"+"?query="+this.value);
 }
于 2011-07-26T16:58:14.627 に答える