开发者

Grab object from a different page but not using the load method

If a user is on Default for example. Click the navigation to go to Page2 I'd like to load the <div> with the id of container and grab a second <div> with the id of includeScripts, but obviously not load this, just capture the text contained therein.

Example of Default:

<div id="mainContentContainer">
    <!-- Main content container -->
</div>

Example of Page 2:

<div id="container"> 
   开发者_如何学C Page 2

</div>

<div id="includeScripts">
    Some Text here...
</div>

Current script looks like this:

$navigation = $("#primaryNavigation").delegate('ul li a', 'click', function () {

// Load the container information into the MainContainer div located on Default
$('#mainContentContainer').load($(this).attr('href') + ' #container'); 

// Load the 'includeScripts' div and grab the text

          $.ajax({
            url: $(this).attr('href'),
            context: document.body,
            success: function () {
                console.log('success'); 
            }

    });

I thought maybe using the ajax method jQuery provides would work but apparently not.

If my question is unclear please let me know.


Why don't you just create a second div on your "Default" page that you will load the text from the "includeScripts" div into, and set that div's display to none.

From there you would be have that script text available in your Default page.


If I understand your question correctly it should be something like this:

$.ajax({
    url: $(this).attr('href'),
    dataType: 'html',
    context: '#mainContentContainer',
    success: function (html) {
        var text = $(html)
            .find('#container')
            .appendTo(this).end()
            .find('#includeScripts')
            .text();

        console.log(text);
    }
});


This is what I ended up doing... Very similar to Josiah's answer with a minor tweak

$.ajax({
        url: $(this).attr('href'),
        dataType: 'html',
        context: '#mainContentContainer',
        success: function (html) {
                console.log($(html).filter('#includeScripts').text());
                console.log($(html).filter('#includeStylesheets').text());
      }});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜