Remove ajax call from regular links with jQuery Mobile

非 Y 不嫁゛ 提交于 2019-12-29 01:36:15

问题


Using jQuery Mobile I would like to disable the ajax call on links within a specific part of the DOM.

I do not want to put a

data-ajax = false

every time I don't want to use the jquerymobile ajax.

For example, any link that is a child of 'content':

<div class="content">
    <a href="http://externalwebsite.com">External Link</a>
</div>

I would like to add the 'data-ajax = false' onto every link that is a child of 'content'

Is there a way to do this with jquery?


回答1:


If you want to disable the ajax link behaviour from an anchor tag, you can put rel=external in the link and the link will load without ajax and your url will then be usual.

http://jquerymobile.com/demos/1.0a4.1/#docs/pages/docs-navmodel.html

<a href="User/somepage" rel="external" />I wont be using ajax for navigation</a>

If you want to do this in jQuery for some a tags inside content div, you may try like this

$(function(){
  $(".content a").each(function(){
    $(this).attr("rel","external");
  });
});

Here is a sample http://jsfiddle.net/4WEBk/3/

The more Simplified version. (Thanks to tandu for pointing )

$(function(){
  $(".content a").attr("rel","external");
});



回答2:


$(".content a").attr('data-ajax', false);



回答3:


I had to add rel="external" and target="_self" also to make it work.

Under certain conditions, normal http requests will be used instead of Ajax requests. One case where this is true is when linking to pages on external websites. You can also specify that a normal http request be made through the following link attributes:

  • rel=external

  • target (with any value, such as "_blank")



来源:https://stackoverflow.com/questions/10320005/remove-ajax-call-from-regular-links-with-jquery-mobile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!