Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events
  • jQuery Effects
  • jQuery Traversing
  • jQuery HTML & CSS
  • jQuery AJAX
  • jQuery Properties
  • jQuery Examples
  • jQuery Interview Questions
  • jQuery Plugins
  • jQuery Cheat Sheet
  • jQuery UI
  • jQuery Mobile
  • jQWidgets
  • Easy UI
  • Web Technology
Open In App
Next Article:
JQuery | parseJSON() method
Next article icon

jQuery getJSON() Method

Last Updated : 12 Jul, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

In this article, we will learn about the getJSON() method in jQuery, along with understanding their implementation through the example. jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous for its philosophy of “Write less, do more". 

The getJSON() method in jQuery fetches JSON-encoded data from the server using a GET HTTP request.

Syntax:

$(selector).getJSON(url,data,success(data,status,xhr))

Parameters: This method accepts three parameters as mentioned above and described below:

  • url: It is a required parameter. It is used to specify the URL in the form of a string to which the request is sent
  • data: It is an optional parameter that specifies data that will be sent to the server.
  • callback: It is also an optional parameter that runs when the request succeeds.

Return Value: It returns XMLHttpRequest object.

Please refer to the jQuery Tutorial and jQuery Examples articles for further details.

Example: The below example illustrates the getJSON() method in jQuery.

employee.json file:

{ 
"name": "Tony Stark", 
"age" : "53", 
"role": "Techincal content writer", 
"company":"Geeks for Geeks" 
}

Here, we get the JSON file and displays its content.

HTML
<!DOCTYPE html> <html>  <head>     <title>jQuery getJSON() Method</title>     <script src= "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">     </script>      <!-- Script to get JSON file and display its content -->     <script type="text/javascript" language="javascript">         $(document).ready(function () {             $("#fetch").click(function (event) {                 $.getJSON('employee.json', function (emp) {                     $('#display').html('<p> Name: ' + emp.name + '</p>');                     $('#display').append('<p>Age : ' + emp.age + '</p>');                     $('#display').append('<p> Role: ' + emp.role + '</p>');                     $('#display').append('<p> Company: '                         + emp.company                         + '</p>');                 });             });         });     </script> </head>  <body>      <p> Click on the button to fetch employee data </p>      <div id="display"           style="background-color:#39B54A;">     </div>     <input type="button"             id="fetch"             value="Fetch Employee Data" /> </body>  </html> 

Output:

 getJSON() Method

Next Article
JQuery | parseJSON() method

A

AnkitMishra16
Improve
Article Tags :
  • Web Technologies
  • JQuery
  • jQuery-Methods

Similar Reads

    jQuery ajax() Method
    The jQuery ajax() method is used to perform asynchronous HTTP requests, allowing you to load data from a server without reloading the webpage. It provides a flexible way to interact with remote servers using GET, POST, or other HTTP methods, supporting various data formats.Syntax:$.ajax({name:value,
    4 min read
    jQuery ajaxSetup() Method
    The ajaxSetup() method in jQuery is used to set the default values for future AJAX requests. Syntax: $.ajaxSetup( {name:value, name:value, ... } )Parameters: type: It is used to specify the type of request.url: It is used to specify the URL to send the request to.username: It is used to specify a us
    3 min read
    jQuery | get() Method
    In jQuery .get() method loads data from the server by using the GET HTTP request. This method returns XMLHttpRequest object. Syntax $.get( url, [data], [callback], [type] ) Parameters url : String containing the URL at which request is to be sent data : This is an optional parameter that represents
    2 min read
    jQuery getJSON() Method
    In this article, we will learn about the getJSON() method in jQuery, along with understanding their implementation through the example. jQuery is an open-source JavaScript library that simplifies the interactions between an HTML/CSS document, It is widely famous for its philosophy of “Write less, do
    2 min read
    JQuery | parseJSON() method
    This parseJSON() method in jQuery takes a well-formed JSON string and returns the resulting JavaScript value. Syntax: jQuery.parseJSON( json )Parameters: The parseXML() method accepts only one parameter that is mentioned above and described below: json: This parameter is the well-formed JSON string
    2 min read
    jQuery getScript() Method
    The getScript() method in jQuery is used to run a JavaScript using AJAX HTTP GET request. Syntax: $(selector).getScript(url, success(response, status))Parameters: It contains two parameters as mentioned above and described below: url: It is a required parameter. It holds the url to whom the request
    2 min read
    jQuery param() method
    The param() method in jQuery is used to create a serialized representation of an object. Syntax: $.param( object, trad )Parameters: This method accepts two parameters as mentioned above and described below: object: It is a mandatory parameter that is used to specify an array or object to serialize.t
    2 min read
    jQuery | post() Method
    The post() method in jQuery loads the page from server using POST HTTP request and returns XMLHttpRequest object. Syntax: $.post( url, data, callback_function, data_type ) Parameters: This method accepts four parameters as mentioned above and described below: url: It is the required parameter and us
    2 min read
    jQuery ajaxComplete() Method
    The ajaxComplete() method is used to specify a function to be run when an AJAX request completes. Syntax: $(document).ajaxComplete(function(event, xhr, options))Parameter: event: It contains the event object. xhr: It contains the XMLHttpRequest object. options: It contains the used options in AJAX r
    2 min read
    jQuery ajaxError() Method
    The ajaxError() method in jQuery is used to specify a function to be run when an AJAX request fails. Syntax: $(document).ajaxError( function(event, xhr, options, exc) )Parameters: This method accepts single parameter function which is mandatory. This function accepts four parameters which are listed
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences