JQuery Ajax Call

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
ATLChris
Forum Newbie
Posts: 15
Joined: Mon Feb 09, 2009 6:21 am
Location: Atlanta, GA

JQuery Ajax Call

Post 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?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: JQuery Ajax Call

Post 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.
User avatar
tr0gd0rr
Forum Contributor
Posts: 305
Joined: Thu May 11, 2006 8:58 pm
Location: Utah, USA

Re: JQuery Ajax Call

Post 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.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: JQuery Ajax Call

Post 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.
d.unicorn
Forum Newbie
Posts: 2
Joined: Tue Sep 08, 2009 1:23 pm

Re: JQuery Ajax Call

Post 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);
}
})
})
Post Reply