【问题标题】:jq_link_to_remote submit formjq_link_to_remote 提交表单
【发布时间】:2012-07-28 14:51:27
【问题描述】:

如何使用 jq_link_to_remote 通过 POST 提交表单并更新 div?

testSuccess.php

 <div id="list">
 <form name="list" action="<?= url_for('shoppinglist/update'); ?>" method="post">
 .
 //some input text.
 .
 <?php
 function addlink() {

$linkname = "+";
 return jq_link_to_remote($linkname, array(
    'update' => 'list',
    'url' => 'shoppinglist/update',
    'data' => 'list', //this might be the problem.
    'loading' => jq_visual_effect('fadeIn', '#indicator'),
    'complete' => jq_visual_effect('fadeOut', '#indicator'),
    'method' => 'post',
 ));

}
echo addlink();
?>
<INPUT TYPE="button" VALUE="Cart" onClick="submitForm()">
</form>
</div>

更新

当我使用这个时:

<?php
echo form_remote_tag( array(
'url'      => '@shoppinglist/update', // even when I don't type "@“
'update'   => 'list',
'loading'  => jq_visual_effect('fadeIn', '#indicator'),
'complete' => jq_visual_effect('fadeOut', '#indicator'),
 ));
 ?>

错误:调用未定义的函数 form_remote_tag()

当我使用这个时:

function addlink() {

$linkname = "+";
 return jq_form_remote_tag($linkname, array(
     'url' => '@shoppinglist/update', // even when I don't type "@“
    'update' => 'list',
    'loading' => jq_visual_effect('fadeIn', '#indicator'),
    'complete' => jq_visual_effect('fadeOut', '#indicator'),
    'method' => 'post',
 ));

}
//I just echo a link!
echo  addlink();

错误:注意:未定义索引:url in ... JQueryHelper.php 第 353 和 410 行

【问题讨论】:

    标签: php jquery ajax symfony1 symfony-1.4


    【解决方案1】:

    你为什么不改用jq_form_remote_tag

    <?php echo jq_form_remote_tag(array(
      'url'      => 'shoppinglist/update',
      'update'   => 'list',
      'loading'  => jq_visual_effect('fadeIn', '#indicator'),
      'complete' => jq_visual_effect('fadeOut', '#indicator'),
    )) ?>
    

    我不明白addlinksubmitForm 之间的区别?

    编辑:

    嗯,你应该这样设置你的模板

    <div id="list">
      <?php echo jq_form_remote_tag(array(
      'url'      => 'shoppinglist/update',
      'update'   => 'list',
      'loading'  => jq_visual_effect('fadeIn', '#indicator'),
      'complete' => jq_visual_effect('fadeOut', '#indicator'),
      )) ?>
    
        //some input text.
    
        <input type="submit" value="Cart" />
      </form>
    </div>
    

    【讨论】:

    • 谢谢。 submitForm() 是一个 C&P 错误。当我执行您的解决方案时,我收到错误:第 353 行上的未定义索引 url jQuery Helper.php。为什么?
    • 不知道,353行是什么?你 c/p 我的代码是什么?你能用这些信息更新你的问题吗(并修复你关于submitForm的坏c/p?
    • symfony 或 php 如何知道按钮从 jq_form_remote_tag 获取操作?我看不出这有什么关系?我的意思是从 echo jq_form_remote_tag 我看不到任何按钮。而不是我原来的帖子 jq_link_to_remote。只是想知道和理解它。
    • jq_form_remote_tag 不会显示任何按钮。当您点击提交按钮时,它将作用于提交事件以使用 ajax 发送表单。这就是为什么你可以有一个基本的提交按钮,它会使用 ajax 发送数据。
    • 好的,我明白了。但是为什么 jq_form_remote_tag 不去 'url' => 'shoppinglist/update'。它转到我将调用整个站点的原始操作,例如'购物清单/索引'。
    猜你喜欢
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多