Page 1 of 1

JQuery Ajax Call

Posted: Tue Aug 18, 2009 3:39 pm
by ATLChris
I am using jQuery to do a ajax call:

Code: Select all

 
var loadUrl = "organize.php";
$("#loadPortfolio").click(function(){
    $("#result").html(ajax_load).load(loadUrl, "location=1");
});
 
Everything loads just fine, but what I found is that other jQuery code inside the newly loaded data doesn't work. Do I need to link to the javascript files again from newly loaded data?

I hope that makes sense. Are there any tricks to making javascript code work in a section that was loaded via Ajax and jQuery?

Re: JQuery Ajax Call

Posted: Tue Aug 18, 2009 4:32 pm
by jackpf
I might be wrong, but I don't think javascript executes when loaded with ajax. At least, I've noticed that on my own site. Not sure if there's a way around it.

Re: JQuery Ajax Call

Posted: Tue Aug 18, 2009 4:36 pm
by tr0gd0rr
You may just need to eval the scripts in the HTML. When setting the innerHTML of an element with content that contains <script> tags, the javascript is not run. I couldn't see easily how to use the evalScripts() method for jQuery, but it looks like in jQuery 1.2 it evals scripts automatically.

Re: JQuery Ajax Call

Posted: Tue Aug 18, 2009 4:39 pm
by jackpf
Oh right...I don't actually use jquery. I just thought I'd share my knowledge of javascript not executing ^^

That makes sense though.

Re: JQuery Ajax Call

Posted: Tue Sep 15, 2009 7:38 am
by d.unicorn
try this

$(document).ready(function(){

$.ajax({
url:"The URL of the php script",
type:"GET or POST",
data:"Request Data",
success:function(msg){
$("#container").html(msg);
}
})
})