views:

69

answers:

3

hey guys, 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.

+2  A: 

use .get and replace the element

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

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

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


});
redsquare
This replaces the element with the entire page, it's not selecting the element...
Nick Craver
Sorry, not used to requests responding with full documents!
redsquare
+4  A: 

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.

Nick Craver
this would actually work, but I'm now having quite a taugh problem. if i do so, only the contens of the div get replaced. somehow I can't even explain my problem. let's try: for instance, the page i'm actually trying to reload (at least a part of it) is having a jquery.unload event. if i just load the #server_view insides, the unload method won't work anymore. the unload would actually hide() something inside the div im reloading. is that comprehensible? not really i guess.
moreover, there are links inside this #server_view div which have an e.preventDefault() on them. if i reload the content once. the preventDefault() wouldn't work any longer and the it's not doing the reload again.actually non of my jquery isn't working anymore if i do the reload once. that's weird! even if i load the jquery inside the head-tag.
@mathiregister - If there are links you want to prevent default you'll either need to re-run the handlers...or use `.live()` handlers in the first place :) The `unload` event...I'm not really sure from your description what's going on, perhaps if you an describe it a bit more I'll get the idea?
Nick Craver
hurray, live() rules! ;) thanks mate. i now got everything. i solved the other problem as well. load has a callback function so i'm just hiding my ajax-spinner with this and not on unload. thanks again, your awesome.
@mathiregister - Welcome :)
Nick Craver
A: 

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

manoelhc