this web service running properly individually but but when i am calling this through JSON it not reflecting the database please help me
Revision 2
How Can i call this web method through json query and how can i pass value of controls in json method to call web method and how can i show alert box on the bases of returning value from web?
[WebMethod]
public string ChangePass(string UserName,string AltEmail,string OldPass,string NewPass,string ComfPass)
{
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Connect"].ConnectionString);
SqlDataAdapter sp = new SqlDataAdapter("select Password from User_Registration where Password='" + OldPass + "'", con);
DataSet ds = new DataSet();
sp.Fill(ds);
if (ds.Tables[0].Rows.Count != 0)
{
SqlDataAdapter dap = new SqlDataAdapter("update User_Registration set Password='" + ComfPass + "' where Email_Id='" + UserName + "'", con);
DataSet ds1 = new DataSet();
dap.Fill(ds1);
MailMessage mail = new MailMessage("tech@xyz.com", AltEmail);
mail.Body = "Email:-" + mail.From + "<br />" + "New Password:-" + ComfPass;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
NetworkCredential NetCre = new NetworkCredential();
NetCre.UserName = "tech@xyz.com";
NetCre.Password = "abc@123";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetCre;
smtp.Port = 587;
smtp.Send(mail);
return "Password change Successfully";
}
return "Please enter valid old password";
}
JSON CODE:-
<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js">
function changPass() {
try {
alert("ok");
$.ajax({
type: "POST",
url: "http://localhost:12345/WebSite5/ADO.asmx/ChangePassword",
data: "{'UserName':'" + $("txtUserName").val() + "', "
+ "'AltEmail':'" + $("txtAltEmail").val() + "',"
+ "'OldPass':'" + $("txtOldPass").val() + "',"
+ "'NewPass':'" + $("txtNewPass").val() + "',"
+ "'ConfPass':'" + $("txtConfirmPass").val() + "'}",
dataType: "json",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function() { alert("Password Update Successfully"); },
failure: function() { alert("Please Enter Correct Old Password!"); }
});
} catch (e) {
alert(e);
}
}
</script>
Posted 4-May-12 19:04pm
by
Vivek_Sharma.