简体   繁体   English

从页面获取特定内容以通过Ajax插入Bootstrap 3模式

[英]Getting specific content from page to be inserted to bootstrap 3 modal via ajax

I am trying to pull specific content from a page into the bootstrap 3 modal via ajax but can only pull in the whole page. 我试图通过ajax将页面中的特定内容拉入bootstrap 3模态,但只能拉入整个页面。

Here is my jQuery code: 这是我的jQuery代码:

function wineMap() {

    var wh = $(window).height();
    var hh = $('#masthead').height();
    $('.wine-menu #mainstage').css({
        height: wh-hh-80
    });
    $('#wine-map').vectorMap({
        map: 'world_en',
        backgroundColor: '#000',
        color: '#ffffff',
        hoverOpacity: 0.7,
        selectedColor: '#666666',
        enableZoom: true,
        scaleColors: ['#ffffff', '#eeeeee'],
        normalizeFunction: 'polynomial',
        onRegionClick: function(element, code, region){
            if (code == 'us')    {
                var url = 'http://cb.dannycheeseman.me/wine-menu/'+code;
            }
            $('#theModal').modal({
                show : true,
                remote: url
            });
        }
    });
}

$(document).ready(function(e) {
    wineMap();
});

Here is the url http://cb.dannycheeseman.me/wine-menu/ (click on the USA) 这是网址http://cb.dannycheeseman.me/wine-menu/ (点击美国)

I have tried: 我努力了:

function wineMap() {

    var wh = $(window).height();
    var hh = $('#masthead').height();
    $('.wine-menu #mainstage').css({
        height: wh-hh-80
    });
    $('#wine-map').vectorMap({
        map: 'world_en',
        backgroundColor: '#000',
        color: '#ffffff',
        hoverOpacity: 0.7,
        selectedColor: '#666666',
        enableZoom: true,
        scaleColors: ['#ffffff', '#eeeeee'],
        normalizeFunction: 'polynomial',
        onRegionClick: function(element, code, region){
            if (code == 'us')    {
                var url = 'http://cb.dannycheeseman.me/wine-menu/'+code;
            }
            $('#theModal').modal({
                show : true,
                remote: url+'#menu-home-location'
            });
        }
    });
}

$(document).ready(function(e) {
    wineMap();
});

Note the: 注意:

                remote: url+'#menu-home-location'

I would expect that to pull in just the content of that id but it is still pulling in the whole page.. 我希望可以仅提取该id的内容,但仍会提取整个页面。

Regards 问候

Ok, so after reading up on the jQuery load function I have realised that you need a space before the id of the content you wish to add so: 好的,因此,在阅读了jQuery load函数之后,我意识到您想要添加的内容的ID之前需要一个空格,因此:

            $('#theModal').modal({
                show : true,
                remote: url+'#menu-home-location'
            });

Becomes: 成为:

            $('#theModal').modal({
                show : true,
                remote: url+' #menu-home-location'
            });

And it works great. 而且效果很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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