Introduction
- JSON is a lightweight data-interchange format.
- JSON is language independent
- JSON is "self-describing" and easy to understand.
Syntax
In client-side.
- function <FUNCTION NAME> (<PARAMETER OPTIONAL>) {
- $.ajax({
- type: <GET/POST>,
- contentType: "application/json; charset=utf-8",
- url: <TARGET URL>\<SERVER SIDE METHOF NAME>,
- data: JSON.stringify({ <PARAMETER TO SEND>: <VALUE> }),
- async: <true/false>,
- dataType: "json",
- success: function (data) {<TO DO>
- returnflag = true;
- },
- error: function (result) {
- returnflag = null;
- }
- });
- }
- [WebMethod]
- public static string <SERVER SIDE METHOF NAME> (<PARAMETER>)
- {
- ….
- …
- Return XYZ;;
- }
- <asp:TextBox Width="80px" MaxLength="32" ID="txtRegnum" runat="server"onblur="getName();" ></asp:TextBox>
- <asp:Label ID="lblStudentName" runat="server" ></asp:Label>
- function getName() {
- var regNum = '';
- var returnflag;
- regNum = document.getElementById('txtRegnum').value;
- if (regNum != '') {
- $.ajax({
- type: "POST",
- contentType: "application/json; charset=utf-8",
- url: "default.aspx/getStudentName",
- data: JSON.stringify({ RegNum: regNum }),
- async: false,
- dataType: "json",
- success: function (data) {
- if (data.d == '') {
- document.getElementById('lblStudentName').innerHTML = '';
- }
- document.getElementById('lblStudentName').innerHTML = data.d;
- returnflag = true;
- },
- error: function (result) {
- returnflag = null;
- }
- });
- }
- }
- [WebMethod]
- public static string getStudentName (string RegNum )
- {
- ….
- …
- Return XYZ;;
- }

Santhakumar MunuswamyPosted Jun 22, 2015, 2:45 PM
Nice