开发者

Can only access jQuery.ajax not $.ajax [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜