I have a strange problem. I have loaded jquery-min javascript in my file. But I can only access jQuery.ajax not $.ajax. $.ajax is said to be undefin开发者_如何学编程ed. Why is that?
Are you using another framework which takes the $
function?
Look into JQuery's noConflict setup
Example:
<script type="text/javascript" src="other_lib.js"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$.noConflict();
jQuery(document).ready(function($) {
// Code that uses jQuery's $ can follow here.
});
// Code that uses other library's $ can follow here.
</script>
You can even assign a different alias to JQuery other than $
:
var j = jQuery.noConflict();
// Do something with jQuery
j("div p").hide();
// Do something with another library's $()
$("content").style.display = 'none';
You can easily fix this by using a closure as well.
(function( $ ){
// Your jQuery code here.
})( jQuery );
精彩评论