$.getJSON()
MethodYou can simply use the $.getJSON()
method to load local JSON file from the server using a GET HTTP request. If the JSON file contains a syntax error, the request will usually fail silently.
Let's try out the following example to understand how it basically works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Loading Local JSON File</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(){
$.getJSON("test.json", function(data){
console.log(data.name); // Prints: Harry
console.log(data.age); // Prints: 14
}).fail(function(){
console.log("An error has occurred.");
});
});
</script>
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to Strip All Spaces Out of a String in PHP
Use the PHP str_replace() Function Yo...How to use the PHP Ternary Operator
If else condition is used to execute the...Laravel 5.5 - Delete Confirm Bootstrap jQuery Model
Hello, everyone in this article we are s...How to find IP address on Ubuntu
Want to know what is your Ubuntu desktop...JWT - Authentication API in Laravel7
This is a comprehensive Laravel 7 JWT Au...