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 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥15 DruidDataSource一直closing
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据