Web
Analytics
Jquery JSON Ajax Example - Tutorial

For Consultation : +91 9887575540

Stay Connected :

<!DOCTYPE html>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title></title>
<script src=”jquery-2.2.3.js”></script>
<script>
$(document).ready(function () {
$(“#btn1”).click(function () {

$.ajax({
type: “POST”,
contentType: “application/json; charset=utf-8”,
url: “Default.aspx/CheckLogin”,
data: “{‘username’:'” + $(“#username”).val() + “‘,’password’:'” + $(“#password”).val() + “‘}”,
dataType: “json”,
success: function (data) {
var obj = data.d;
alert(data);

},
error: function (result) {
alert(“Error”);
}
});
})
})

</script>
</head>
<body>
<input type=”text” id=”username” name=”username” value=” ” /><br />
<input type=”text” id=”password” name=”password” value=” ” /><br />
<input type=”button” id=”btn1″ name=”btn1″ value=”SignIn” />
</body>
</html>

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//Response.Write(CheckLogin(“ceg”,”ceg123″));
}
[WebMethod]

public static string CheckLogin(string username, string password)
{

string msg = “”;
if (username == “ceg” & password == “ceg123”)
{
msg = “Valid Username or password”;
}
else
{
msg = “InValid Username or password”;
}
return msg;
}
}




Select your currency