Regarding AJAX using JQuery

$.get(“https://jsonplaceholder.typicode.com/users”,function(response){
console.log(response);
})
Whenever i am writing above code i am getting error like Uncaught TypeError: $.get is not a function
@anudeepmarlapalli22

1 Like

Hi @vineethkumarmudham
The error you’re encountering, “Uncaught TypeError: $.get is not a function,” typically indicates that the $ symbol is not recognized as a reference to the jQuery library. The $.get function is a part of jQuery, and this error suggests that jQuery might not be properly loaded or initialized in your project.

Here are a few steps you can take to troubleshoot and fix the issue:

  1. Check jQuery Inclusion: Make sure you have included the jQuery library in your HTML file before using its functions. You can do this by adding the following line within the <head> section of your HTML file:
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

Replace "https://code.jquery.com/jquery-3.6.0.min.js" with the appropriate URL for the version of jQuery you want to use.

  1. Correct Syntax: Ensure that your JavaScript code is written correctly. Double-check for any typos or syntax errors. In your case, the code you provided seems correct.
  2. jQuery Conflict: Sometimes, there might be conflicts with other libraries that also use the $ symbol. To avoid conflicts, you can use the jQuery keyword instead of $. Here’s your code with jQuery:
jQuery.get("https://jsonplaceholder.typicode.com/users", function(response) {
    console.log(response);
});
  1. Document Ready: Wrap your jQuery code within the $(document).ready() function to ensure that the code executes after the DOM is fully loaded. This is especially important if your script is placed in the <head> section of the HTML.
$(document).ready(function() {
    $.get("https://jsonplaceholder.typicode.com/users", function(response) {
        console.log(response);
    });
});
  1. Console Errors: Check your browser’s console for any other error messages or warnings. Sometimes, there might be additional information that can help pinpoint the issue.
  2. Network Issues: If you’re loading the page from a local file system (file://), some browsers might restrict AJAX requests. Try opening your HTML file from a web server (e.g., using http:// or https://) to see if the issue persists.

If you follow these steps and the issue still persists, please provide more information about your environment, how you’re including jQuery, and any other relevant details that might help diagnose the problem.