Jquery Mobile AJAX 链接冲突
我对 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>`
I'm relatively new to JQuery/JS so if you could please make your answers idiot proof it would be appreciated.
Can anyone suggest how I can edit Jquery Mobile so its AJAX link features are only applied to specific classes.
Problem is links that have their own separate AJAX functions are being overrun by JQuery Mobile.
I've tried "ajaxEnabled: false"
on specific classes but this disables all AJAX features, where I need to disable just ajax links from JQuery Mobile.
I've search the problem and only found outdated info on using .ajaxLinksEnabled : false;
which no longer seems to be supported in Alpha 4, eg:
<code>
$(document).live("mobileinit", function() {
$.mobile.ajaxLinksEnabled :false;
$.mobile.ajaxFormsEnabled :false;
});
</code>
Any help would be great appreciated as spent hours trying to sort this now.
UPDATE:
I'm trying to use 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>`
This stops the JQ Mobile AJAX link BUT fails to call functionhandleAddToCart
HTML and 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>`
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将
data-ajax="false"
添加到链接中,这是在链接上禁用 Ajax 的 jquery 移动方式。如果您想要一个纯类解决方案,可以在绑定新的 ajax 函数之前尝试在链接上使用
.die()
。http://jquerymobile.com/demos/1.0rc2/docs/pages /page-links.html
You could add
data-ajax="false"
to your links, it's the jquery mobile way to disable Ajax on a link.If you want a pure Class solution, maybe try to
.die()
on your link before binding your new ajax function.http://jquerymobile.com/demos/1.0rc2/docs/pages/page-links.html
HTML:
JavaScript:
如果 jQuery Mobile 在链接上运行其自己的处理程序时仍然遇到问题,请将
rel="external"
添加到链接。以下是 jQuery Mobile 中链接的文档:http://jquerymobile。 com/demos/1.0rc2/docs/pages/page-links.html
HTML:
JavaScript:
If you are still having issues with jQuery Mobile running its own handler on the link, add
rel="external"
to the links.Here is the documentation for linking in jQuery Mobile: http://jquerymobile.com/demos/1.0rc2/docs/pages/page-links.html