abc

Share This blog with your friends, so that we can improve more & more . our aim is to easy & simple way of learning.

4/06/2018

Advanced Session on JSON how object declare in javascript




Connect Laptop To Computer and laptop To TV Connectivity.









hi every one today i am going to start session 7 .
let us know some short review on JSON

what is JSON.

JSON: JavaScript Object Notation.
JSON -- > a syntax for storing and exchanging data.
JSON ---> text, written with JavaScript object notation.

var abc = '{ "age":26, "city :PUNE",''name:siddhanam" }';
var anobj = JSON.parse(myJSON);
document.getElementById("abc").innerHTML = myObj.name;

<h2>Convert a string written in JSON format, into a JavaScript object.</h2>
<p id="abc"></p>

if you look at above example you can see declaration of object to variable in short declare, store , transfer in DOM this are main working of JSON.
 above example uses json parse method,
what is json parse???
common use of JSON is to exchange data to/from a web server. When receiving data from a web server, the data is always a string. Parse the data with JSON.parse(), and the data becomes a JavaScript object. 

in above figure shows how json parse  working.

now let us see JSON with php

<!DOCTYPE html>
<html>
<body>

<h2>Example of JSON.</h2>

<p id="abc"></p>

<script>

var xmlhttp = new XMLHttpRequest();

xmlhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        var myObj = JSON.parse(this.responseText);
        document.getElementById("demo").innerHTML = myObj[2];
    }
};
xmlhttp.open("GET", "trial.php", true);
xmlhttp.send();

</script>

</body>
</html>

in above code there is getting result of trial.php file and assign value to demo div.
suppose you type an address in trial.php or anything data by using this xmlhttp request & get method browser will show result.

json is not need any external installation .
our aim is to gain & share more & more knowledge.
you can comment if any improvement wants or if you want discuss any specific topic.
please share with your friends & all . thanks for viewing this blog. will see more detail in next session.



1 comment:

An Introduction to the Laravel Framework: What It Is and Why You Should Use It

  If you're a PHP developer looking for a modern, efficient, and powerful framework to build web applications, look no further than Lara...