Cannot use $ .get on a WordPress page.

I am trying to use the ajax $ .get () request to display calculated data on one of my WordPress pages. I did not decide if I was going to host the php calculation file on another server or the one on which WordPress is hosted (do not think that it will matter anyway from the moment of requesting the data). I want to add the following code to the header.php file, or even better, on the page created in wp-admin:

<script> $(document).ready(function(){ $.get("http://my-other-website.com/parse-list.php",function(data){ alert(data); }); }); </script> 

I know that this is a basic function, but I'm just very fixated on how it does not work in WordPress, but it works when on my other server that does not host WordPress. I tested jQuery to make sure it loads properly, with a simple warning ("hey"); and the warning works just fine. Who else has this problem? Any help would be greatly appreciated!

+1
source share
1 answer

jQuery in WordPress works in noConflict mode, which means that the global $ shortcut for jQuery is not available. Replace the code as follows:

 <script> jQuery(document).ready(function($){ $.get("http://my-other-website.com/parse-list.php",function(data){ alert(data); }); }); </script> 
+6
source

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


All Articles