Uncaught ReferenceError: $ not defined

I get an undefined error and I don’t know how to fix it.

Here is my code:

<script type="text/javascript"> function returnBlurayDisc(member_id){ var xmlhttp; if (window.XMLHttpRequest){ xmlhttp=new XMLHttpRequest(); }else{ xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function(){ if (xmlhttp.readyState==4 && xmlhttp.status==200){ document.getElementById("popup_container").innerHTML=xmlhttp.responseText; $("#GrayBackground").css({'height':'1900px','display':'inline'}); } } xmlhttp.open("GET","ajax/returnAjax.php?member_id="+member_id+"&name="+name); xmlhttp.send(); } </script> 

Error: Uncaught ReferenceError: $ not defined. Please help me.

+4
source share
2 answers

This line:

 $("#GrayBackground").css({'height':'1900px','display':'inline'}); 

uses jQuery (via the $ function), which is a library that you should include on your page if you want this line of code to be there.

Put this at the top of the page to check:

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

It is worth noting that if you want to accept jQuery - in many cases this is a good idea, you can use it to simplify a bunch of things, including the AJAX request that you are doing now manually.

+5
source

$ in your code most likely refers to the jQuery library. So, make sure you include the jQuery library file in your document.

If you use a CDN, then you should include a similar tag, as shown below, in the head section of your document.

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> 

This includes the jQuery library in your document, and you can finally use the $ elements to target.

+2
source

Source: https://habr.com/ru/post/1434139/


All Articles