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
    
            }
        });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵