404 Not Found
404 Not Found

Reputation: 1223

jquery lib is not including

i have developed my plugin and i got some strange problem. when i am including Jquery lib file with this code

   <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

it's working fine but when i am including Jquery Lib with this code it's not working

   <script src="<?php echo plugins_url(); ?> /kp_contactus/js/jquery.js"> </script>

the path is proper i have checked and local Jquery lib version is jQuery v1.10.2

i am getting console error is...

Uncaught TypeError: Property '$' of object [object Object] is not a function ?page_id=19:108 (anonymous function)

can anybody suggest what's going wrong with it?

   $('#contact').validate({
        /* Making ajax request on successfull submition*/
       submitHandler : function (form){
           var name=$("#firstname").val();
           var email=$("#useremail").val();
           var contact=$("#mobile").val();
           var type=$("#type").val();
           var msg=$("#message").val();
           $("#send").attr("disabled",true).html("Sending");
           var data = { 'name': name, 'email' : email, 'contact' : contact, 'type' : type, 'msg' : msg };
           $.ajax({
               url : '<?php echo plugins_url();?>'+'/kp_contactus/kp_contact_config.php',
               type : 'POST',
               data : {contact:JSON.stringify(data)},
               success : function (msg)
               {
                  $("#info").fadeIn().html(msg).fadeOut(5000);
                  $("#send").attr("disabled",false).html("Send");
                  $("#contact").find("input").val("");
                  $("#contact").find("textarea").val("");
               }
           })
       },

Upvotes: 0

Views: 137

Answers (3)

Zaheer Ahmed
Zaheer Ahmed

Reputation: 28558

Sometime different libraries conflict over $.

<script src="other_lib.js"></script>
<script src="jquery.js"></script>
<script>
$.noConflict(); // releases $ from jQuery

jQuery( document ).ready(  // you must need to use jQuery here

 function( $ ) { // you passed $ as a parameter for jQuery

   // Use jQuery code with $ keyword
    $( "div a" ).show();
 });

// Use other library with $ keyword
$("content").style.display = "none";

</script>

Upvotes: 1

tariq
tariq

Reputation: 2258

Many JavaScript libraries use $ as a function or variable name, just as jQuery does. In jQuery's case, $ is just an alias for jQuery, so all functionality is available without using $. There is a possibility that its conflicting so use jQuery keyword instead of $

with reference to your this comment "now i am getting this error "Uncaught ReferenceError: JQuery is not defined" this implies that the library is not being found double check for this.

Also as pointed by Zaheer put in http:// (As pointed out by others not required necessarily)

Upvotes: 1

C. S.
C. S.

Reputation: 813

When writing jQuery code for WordPress, I often use jQuery('#getId') instead of $('#getId') and it works, have you tried that?

Here is an interesting and brief article that can help explain it.

Upvotes: 2

Related Questions