Jquery Mobile AJAX链接冲突

时间:2011-10-21 20:33:51

标签: jquery ajax mobile

我对JQuery / JS比较陌生,所以如果你能把你的答案做成白痴证明,我们将不胜感激。

任何人都可以建议我如何编辑Jquery Mobile,以便其AJAX链接功能仅适用于特定的类。

问题是JQuery Mobile正在覆盖具有各自独立AJAX功能的链接。

我在特定的类上尝试了"ajaxEnabled: false",但这会禁用所有AJAX功能,我需要从JQuery Mobile中禁用ajax链接。

我已经搜索了这个问题,并且只发现使用{4}似乎不再支持的.ajaxLinksEnabled : false; 的过时信息,例如:

<code>
$(document).live("mobileinit", function() {
$.mobile.ajaxLinksEnabled :false;
$.mobile.ajaxFormsEnabled :false;
});
</code>

任何帮助都会非常感激,因为现在花费数小时试图对此进行排序。

更新

我正在尝试使用preventDefault:

`<script>
$('[data-role="page"]').bind('pageinit', function () {
    $('.addtocart_form').bind('click', function (e) {
        e.preventDefault();
        //add your custom ajax call here
         $('#addcartsubmit1').click(handleAddToCart);
    });
});
</script>` 

这会停止JQ Mobile AJAX链接但未能调用 functionhandleAddToCart

HTML和PHP:

     `<form action="<?php echo $mm_action_url ?>index.php" method="post" name="addtocart" id="addtocart<?php echo $i ?>" class="addtocart_form" <?php if( $this->get_cfg( 'useAjaxCartActions', 1 ) && !$notify ) { echo 'onsubmit="handleAddToCart( this.id );return false;"'; } ?>>
  <div class="quantbox"> <?php echo $ps_product_attribute->show_quantity_box($product_id,$product_id); ?><br /></div>
  <div class="bsubmitcart"> <input type="submit" id="addcartsubmit1" style="border:none;" class="<?php echo $button_cls ?>" value="Add to Cart" title="<?php echo $button_lbl ?>" /> </div>`

2 个答案:

答案 0 :(得分:2)

您可以在链接中添加data-ajax="false",这是在链接上禁用Ajax的jquery移动方式。

如果您需要纯类解决方案,可以在绑定新的ajax函数之前尝试在链接上.die()

http://jquerymobile.com/demos/1.0rc2/docs/pages/page-links.html

答案 1 :(得分:0)

HTML:

<a href="#" class=".my-link-class">A Link</a>

JavaScript的:

<script>
$('[data-role="page"]').bind('pageinit', function () {
    $(this).find('.my-link-class').bind('click', function (e) {
        e.preventDefault();
        //add your custom ajax call here
    });
});
</script>

如果您仍然遇到jQuery Mobile在链接上运行自己的处理程序的问题,请将rel="external"添加到链接。

以下是jQuery Mobile中链接的文档:http://jquerymobile.com/demos/1.0rc2/docs/pages/page-links.html