Hi all,
First post. Lurked for a bit while learning and thanks for all the indirect help.
I am having trouble with jumping into ajax.
My old application is all php and I was trying to switch it to ajax for the users who have javascript so there is less page refreshing but also to keep the links working for those who don’t or don’t want the change.
here is a test files I’ve been working with:
<html>
<head><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script></head>
<body>
<div>
<div id="content">
<script type="text/javascript">
$('h1').live('click', function(){ alert('I clicked H1');});
</script>
<h1>Can you see me now?</h1>
</div>
</div>
</body>
</html>
Loaded just like that everything works fine.
However, when loaded via ajax from this file:
(jQuery is loaded above this and this is all in <head>)
$(document).ready(function(){
$.ajax({
url: thisurl,
success: function(html){
var stuff = $("#content", html);
$("#main").empty();
$("#main").append(stuff);
},
error: function() {
alert("AJAX ERROR");
}
});
Everything is closed properly, etc. even if it doesn’t show here, this is just an excerpt
thisurl is a variable that pulls the href field from my hijax script.
so, for the ajax call, i just want the stuff in the content div, and not the whole page. If I take off the Content I get the whole page and all the javascript works. Like this, with the Content, the javascript doesn’t run and doesn’t appear to load into the DOM.
I hope that enough info. Any help would be appreciated as I’m sure I’ve tried all the stupid ideas I’ve had to fix this and none have worked. Thanks!