0

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("");
               }
           })
       },
404 Not Found
  • 1,223
  • 2
  • 22
  • 31

3 Answers3

2

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.

C. S.
  • 805
  • 6
  • 6
1

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)

tariq
  • 2,193
  • 15
  • 26
  • i am getting this error after changing $ with JQuery "i am getting this error "Uncaught ReferenceError: JQuery is not defined" – 404 Not Found Dec 09 '13 at 05:59
1

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>
Zaheer Ahmed
  • 28,160
  • 11
  • 74
  • 110
  • 1
    well caught, u have great eyes :) – tariq Dec 09 '13 at 06:09
  • 2
    It works with //ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js as well. This previous stack can explain a bit http://stackoverflow.com/questions/9646407/two-forward-slashes-in-a-url-src-href-attribute – C. S. Dec 09 '13 at 06:11
  • without http:// it's working... i am using this path in my all project and i didn't get issue till now... – 404 Not Found Dec 09 '13 at 06:11