this problem is driving me crazy… I’m calling a PHP file through Ajax and parse it into my HTML content. I have to do it that way to have dynamic content, without refreshing the page.
My problem is that the parsed code won’t execute any jquery stuff. I need a Jquery slider for example in the PHP file. But it’s parsed as normal HTML and JQuery doesn’t seems to recognise it.
Here’s a sample:
The HTML File:
<html>
<head>
<script src="jquery-1.7.1" type="text/javascript"></script>
<script src="jscroller-0.4.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function()
{
// Add Scroller Object
$jScroller.add("#scroller_container","#scroller","right",1);
// Start Autoscroller
$jScroller.start();
});
</script>
<script type="text/javascript">
function showGet(str)
{
if (str=="")
{
document.getElementById("center").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("content").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","content.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="content">
<input type="button" onclick="showGet(1)" value="showGet">
</div>
<div id="scroller_container">
<div id="scroller">
...[Content]...
</div>
</div>
</body>
</html>
Here’s the content.PHP file:
<?php
echo "
<div id=\"scroller_container\">
<div id=\"scroller\">
...[Content]...
</div>
</div>
"
?>
Executed, the HTML has a Button. If you click the button, it parses content.php into the <div id="content></div>.
The PHP contains the same <div id="scroller" .... as the HTML.
The HTML div works, the one in the PHP file not. WHY???? and how do I get it to work?
Many thx in advance for all hints!!
Loading content using jQuery ajax can be as simple as the following using load() method:
http://api.jquery.com/load/