JSON Ajax
Next ❯jQuery Ajax
- Ajax is used to exchange data from the server without reloading the webpage
- turned_in_notJSON via Ajax
Below example, both your html and json files are in the same folder
"jsoncode.json" file<!DOCTYPE html> <html> <head><title>JSON Example via Ajax</title></head> <body> <p>Hi, My name is <span id="show"></span></p> <script> var xmlhttp = new XMLHttpRequest(); xmlhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { //used to convert incoming JSON String into object var myObj = JSON.parse(this.responseText); //Now you can show your object as per you need document.getElementById("show").innerHTML = myObj.name; } }; xmlhttp.open("GET", "jsoncode.json", true); xmlhttp.send(); </script> </body> </html>
OUTPUT{ "name":"Riya","age":23 }
Hi, My name is
❮ Prev JSON Python
Next ❯jQuery Ajax