Akın Yılmaz
Akın Yılmaz

Reputation: 296

after reload problem with jquery load()

i have a page that : first : i post information and record in into db via ajax
second : i want to show the updated page after recording and these information sections have comments sections that uses Ajax

i use the .load method of jquery ajax to update my information section.but when i use this function, the comment sections which uses ajax do not run.

so what can my problem be?

is there any other options except load for me to update my information sections with running comment sections?

when i use :

function yenile () {
$('#ana_bolum').load('profile.php');
}

it executes the scripts and inside #ana_bolum functions work, but when i use like this :

function yenile () {
$('#ana_bolum').load('profile.php #ana_bolum');
}

it does not execute scripts and functions in #ana_bolum does not work. like said in .load() document in jquery page. i understand why it does not work.but i want to ask is there another way to accomplish this?

Upvotes: 1

Views: 277

Answers (1)

ThiefMaster
ThiefMaster

Reputation: 318808

It is possible but if you always get a complete document from the server it won't be nice.

The problem is that as soon as you convert the HTML string into DOM nodes the scripts are executed. So at this point you want to attach thes notes to the document so the script works properly. However, when you first want to select something from the DOM (what your #someid selector does), it will happen before it's added to the DOM.

A solution is using dataType: text when retrieving the data, then extracting the part you want using string functions and then use $('#yourelement').html(yourdatastring); to add it to the DOM.

Upvotes: 1

Related Questions