开发者

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

开发者 https://www.devze.com 2023-03-22 14:41 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
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

精彩评论

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