I am trying to display a page using jQuery. AJAX functionality implemented on the page does not work.
I use FF for debugging. When I look at the console panel, I see the following error: "jQuery not defined". Ah, this is easy, I think - maybe the jQuery file was not included correctly or could not be found, etc. So I look at the HTML and click on node - lo and lo, the jQuery script has been CORRECTLY included in the page.
Although none of the other js libraries on pages referenced by jQuery uses '$' (for example, a prototype), I called the noConflict () method in jQuery logic, just in case I use a conflicting library later in the stage.
[change]
I think the problem is with the file I'm using jQuery in the template environment (more precisely, Symfony 1.4). For those who are not familiar with the Symfony template system, in essence, the presentation model consists of a “layout” file (template), which is then drawn up (decorator pattern), with other bits of information (it can be called “page content”,).
The last page looks something like this:
<html>
<head>
<script type="text/javascript" src= "http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" ></script>
</head>
<body>
</body>
</html>
I am loading jQuery into a template (i.e. "layout" in Symfony terminology).
The reason for this is that the JQ library is cached on the client side and available for pages requiring it. Dynamic pages (the contents of which are included in the content section of the layout page) will have their own jQuery logic. This (using the idea of a “wrapper function” presented in Marc Schultea's answer) below:
<script type="text/javascript">
jQuery(function()
{
jQuery.noConflict();
jQuery(document).ready(function(){
jQuery("div.tpaccordion div.accItem").hide();
jQuery("#latestVideosHolder").show();
jQuery("div.tpaccordion h3").click(function(){
jQuery(this).next().slideToggle("slow")
.siblings("div.accItem:visible").slideUp("slow");
jQuery(this).toggleClass("active");
jQuery(this).siblings("h3").removeClass("active");
});
});
});
</script>
** [Edit2] ** . , jQuery .: (