The getJSON() method in jQuery fetches JSON-encoded data from the server using a GET HTTP request.
Parameters: This method accepts three parameters as mentioned above and described below:
- url: It is 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 which specifies data that will be sent to the server.
- callback: It is also an optional parameter which runs when the request succeeds .
Return Value: It returns XMLHttpRequest object.
Below example illustrates the getJSON() method in jQuery:
“name”: “Tony Stark”,
“age” : “53”,
“role”: “Techincal content writer”,
“company”:”Geeks for Geeks”
Example: This example get the JSON file and display its content.
Before Clicking the button:
After Clicking the button:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.