admin管理员组

文章数量:1414908

i'm a little confused.

i want to actually reload the same page and fetch a div with a certain id from it. so i'm trying to reload a part of website into the same part of the website. ;) i know it sounds weird.

somehow i don't get what i'm doing wrong or better how i have to do it.

var $sv = $('#server_view');
$sv.load('/server/ftp/' + goToURL + " #server_view");

so in this case the same div gets loaded into the same div and that's not what i want. it then looks like:

<div id="#server_view"> <div id="#server_view"> blabla</div> blabbla </div>

i actually just want to grab the contents of the div inside and reload them. how can i solve this little problem.

i'm a little confused.

i want to actually reload the same page and fetch a div with a certain id from it. so i'm trying to reload a part of website into the same part of the website. ;) i know it sounds weird.

somehow i don't get what i'm doing wrong or better how i have to do it.

var $sv = $('#server_view');
$sv.load('/server/ftp/' + goToURL + " #server_view");

so in this case the same div gets loaded into the same div and that's not what i want. it then looks like:

<div id="#server_view"> <div id="#server_view"> blabla</div> blabbla </div>

i actually just want to grab the contents of the div inside and reload them. how can i solve this little problem.

Share Improve this question edited Jul 16, 2010 at 0:47 Dagg Nabbit 76.8k19 gold badges114 silver badges142 bronze badges asked Jul 15, 2010 at 23:57 mattmatt 44.5k107 gold badges268 silver badges402 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

You can grab the children with the selector you're passing to .load(), like this:

var $sv = $('#server_view');
$sv.load('/server/ftp/' + goToURL + " #server_view>*");

All we're doing different is getting all direct children to insert using the > child selector.

use .get and replace the element

$.get('/server/ftp/' + goToURL, function(response){

    var newContent = $(response).find('#server_view').html();

    $('#server_view').replaceWith( newContent );


});

Simple end fast.

$( "#content" ).load( "# #content>*" );

if you are using $('#server_view');, you must have DIV ID as server_view, not #server_view

本文标签: javascriptjQuery load method reload same div in divStack Overflow