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 在C#方法中使用了.Refresh();刷新了控件,但是不是最新值
  • ¥30 求一下解题思路,完全不懂。
  • ¥30 关于#硬件工程#的问题:求一下解题思路
  • ¥15 运筹学对偶单纯行法构造扩充问题
  • ¥20 XP系统的老电脑一开机就提示找不到rundll.exe,付费求解
  • ¥15 milvus查询出来的score怎么转换成0-1之间的相似性
  • ¥15 lvgl V9移植到linux开发板
  • ¥15 VB.net中在窗体中创建一个button控件来关闭窗体,但是提示错误,我该怎么办
  • ¥15 网上下载好的程序但是arduinoIDE编程报错,运行不了,哪里出错了,能具体给改一下吗