Introduction
JSON (JavaScript Object Notation) is a lightweight data-interchange format. JSON is a syntax to store and exchange the data. JSON is a text, written with JavaScript object notation.
Exchanging data
JSON.stringify()- Send
JSON.parse() - Receive
Data Format
{ "name":"Sakthi", "Designation":"Software Engineer", "Salary":10000 };
ASP page (or) HTML
- <form id="form2" runat="server">
- <div>
- <script>
- debugger;
- var obj, parameter, xmlhttp, _Obj, x, result = "";
- obj = {
- "Designation": "Software",
- "salary": 10000
- }; // WHERE CONDITION
- dbParam = JSON.stringify(obj); // SEND PARAMETERS
- xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- _Obj = JSON.parse(this.responseText); // RECEIVE
- result += "<table border='1'>"
- for (x in _Obj) {
- result += "<tr><td>" + _Obj[x].val + "</td></tr>";
- }
- result += "</table>"
- document.getElementById("demo").innerHTML = result;
- }
- };
- xmlhttp.open("POST", "./ReadTable.asmx/getdata", true); //METHOD POST–WEBSERVICE PAGE
- xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- xmlhttp.send("x=" + parameter);
- </script>
- <p id="demo"></p>
- </div>
- </form>
- <form id="form2" runat="server">
- <div>
- <script>
- debugger;
- var obj, parameter, xmlhttp, _Obj, x, result = "";
- obj = {
- "Designation": "Software",
- "salary": 10000
- }; // WHERE CONDITION
- dbParam = JSON.stringify(obj); // SEND PARAMETERS
- xmlhttp = new XMLHttpRequest();
- xmlhttp.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200) {
- _Obj = JSON.parse(this.responseText); // RECEIVE
- result += "<table border='1'>"
- for (x in _Obj) {
- result += "<tr><td>" + _Obj[x].val + "</td></tr>";
- }
- result += "</table>"
- document.getElementById("demo").innerHTML = result;
- }
- };
- xmlhttp.open("POST", "./ReadTable.asmx/getdata", true); //METHOD POST–WEBSERVICE PAGE
- xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- xmlhttp.send("x=" + parameter);
- </script>
- <p id="demo"></p>
- </div>
- </form>
Join the conversation! Your thoughts help the community grow.