【问题标题】:Jquery Mobile AJAX Links conflictJquery Mobile AJAX 链接冲突
【发布时间】:2013-07-15 03:40:35
【问题描述】:

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

谁能建议我如何编辑 Jquery Mobile,使其 AJAX 链接功能仅适用于特定类。

问题是具有自己独立 AJAX 功能的链接被 JQuery Mobile 溢出。

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

我搜索了问题,只发现了有关使用 .ajaxLinksEnabled : false; 的过时信息,Alpha 4 似乎不再支持,例如:

<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>`

【问题讨论】:

    标签: jquery ajax mobile


    【解决方案1】:

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

    如果您想要一个纯 Class 解决方案,请在绑定新的 ajax 函数之前尝试在您的链接上.die()

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

    【讨论】:

    • 您好,感谢您的回复,我喜欢堆栈,这个网站是上帝送的!我一直在使用 data-ajax="false",但问题是它似乎删除了所有 ajax 函数。我正在尝试将其构建到 Virtuemart 商店中,我需要 VM 的本机 ajax 才能继续工作,因此只需要禁用移动 JQuery 并让其他 ajax 函数运行
    • 也许使用 .die(click[handler]) 只杀死 Jquery Mobile Ajax 函数?
    • 这似乎是最好的路径。我需要在 JQMobile 中杀死的实时函数是:“$.mobile._registerInternalEvents = function(){”我无法让它停止使用 .die(click, _registerInternalEvents)
    • 好吧,这成功了!我之前的问题是由于 ajax 冲突,但是 var $j = jQuery.noConflict();也解决了这个问题。非常感谢
    【解决方案2】:

    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

    【讨论】:

    • 有趣,我会在此之前给出并报告。谢谢!
    • 好的,preventDefault 会停止 ajax,但是在我使用这个之后我无法调用函数 handleAddToCart://在此处添加您的自定义 ajax 调用 $('#IDname').click(handleAddToCart) ;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 2018-07-06
    • 1970-01-01
    • 2012-03-21
    • 2012-02-29
    • 2012-11-22
    相关资源
    最近更新 更多