简体   繁体   中英

jQuery .get - Specific HTML ID (Not Whole Page)

I am trying to use jQuery ajax to call in a project page.

Assume the xhr variable contains the correct string to the webpage (target page). I have prevented the page as mobile viewport will not load the ajax request.

$('a.project__block').on('click', function(e){

    var $el = $(this),
        viewportWidth = $(window).width();

    if (viewportWidth >= 768){
        e.preventDefault();

        var xhr = $.get($(e.currentTarget).data('href'));

        xhr
            .done(open_overlay)
            .fail(function(){
                alert('Could Not Connect, please report to admin!');
            });

    }
});

function open_overlay(data){
    close_overlay_window();
    $('body').addClass('active--overlay').append(data);
    supporting_code();
}

function close_overlay_window(){
    $('#bravedogers').remove();
    $('body').removeClass('active--overlay');
}

function supporting_code(){
    $('.ajax__close__link').on('click', close_overlay_window);
}

function remove__active__classes(){
    // Is the overlay active? If not dont close!
    if (viewportWidth < 768 && $('body').hasClass('active--overlay')){
        close_overlay_window();
    }
}

I want to target the specific id which remains constant in all the project pages, eg:

<div id="wrapper__container"></div>

At present I am getting this error:

在此处输入图片说明

Ideally can in addition see modernizr being loaded in which causes my page to crash.

Any ideas?

Is this what you're trying to do? Append just the wrapper?

function open_overlay(data){
    close_overlay_window();
    var container = $(data).find('#wrapper__container');
    $('body').addClass('active--overlay').append(container);
    supporting_code();
}

I would see if that makes your warning go away. Just looking at the warning, it looks like Google Maps isn't happy about something.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM