weixin_33693070 2013-11-20 10:40 采纳率: 0%
浏览 61

将.load()更改为$ .ajax jQuery

I want to disable/prevent loading of the page until a JS call has been completed. I understand that the only way to do that is with $.ajax like so:

$.ajax({
 url: "/acme/confirm_authentication.html",
 async: false,
 cache: false,
 success: function(data) {
    // loaded
 } 

Currently, I’m loading a partial page with .load() function like so:

var linkUrl = $('.js-dialog--on-load').attr('dialog-href')  + ' #lga';
showDialogWindow(linkUrl);

function showDialogWindow(linkUrl) {
    $('.container').append($("<div>").load(linkUrl, function(){

    }).addClass('js-dialog'));
}

See demo: http://jsfiddle.net/SQDDD/1/

How can I translate this into an $.ajax call?

Remember, the reason I’m using .load() is so that I can load only part of the website (#lga).

  • 写回答

2条回答 默认 最新

  • weixin_33695082 2013-11-20 10:49
    关注

    Take a look at this example :

    I have this html :

    ...
    <body>
      <a href=""> aaa</a>
      <p>bbb</p>
    
    </body>
    ...
    

    now getting the p element from ajax :

     $.ajax(
        {
            url: 'http://jsbin.com/oFUMOtO/3/quiet',
            type: "GET",
            dataType: 'html',
            success: function (data)
            {
              alert($("<div>").html(data).find( "p" ).text()); //alerts bbb
    
            }
        });
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R