-5

I've tried to load an external javascript (chat app) to my webpage by using below following code and its always giving ReferenceError: $ is not defined while my script and URL to the script is ok.

<script>
$(document).ready(function() {
   $("#customer-chat-button-toggle").click(function() {
         $.getScript('livechat/php/app.php/widget-init.js',function(){  
         async: false;
        })
    });     
});
</script>
Niharika Parida
  • 103
  • 1
  • 1
  • 16
  • 1
    Include jQuery correctly. A valid jQuery script must be referenced, the source JS file must be fetchable, and it must be placed before any script element which wishes to use $. (But make sure to use updated versions than in that question.) – user2864740 Aug 12 '14 at 00:29
  • I've tried with various possibilities – Niharika Parida Aug 12 '14 at 00:38
  • 1
    The error message isn't lying. There are only so many reasons this can occur. Is there a jQuery script specified *before* this script? Does fetching the jQuery source result in a 200 OK response? Has anyone called `jQuery.noConflict`? – user2864740 Aug 12 '14 at 00:39
  • I want to know why my question goes 2 negative mark? Whats makes it so poor ? – Niharika Parida Aug 12 '14 at 00:40
  • 1
    Please add the HTML where you have included your scripts, it would help to identify the error. – Jane S Aug 12 '14 at 00:42

2 Answers2

0

Make sure that jQuery is properly loaded. Use firebug as a Firefox debugger or the Chrome console.

Are you accessing a different domain? If so you will need to use a json callback.

$.ajax({
    url: "http://ihound.com.au/livechat/php/app.php/widget-init.js",
    jsonpCallback: "jsonpcallback",
    jsonp: false,
    dataType: "jsonp"
}).done(function(data){
   console.log(data); // array of objects
});
Lucky Edward
  • 136
  • 11
0

I ran into this editing a weebly site recently and they were including jQuery correctly. I had to reference as jQuery. After further reading their includes I could also get it via $$. The console helped alot:

$

Should yield something like

function (a,b){return new e.fn.init(a,b,h)}

If not try

jQuery

Should return same.

John Kloian
  • 1,414
  • 15
  • 15