I am using AJAX
call from my Html page to call a method from my asmx.cs file, using below code:
<script type="text/javascript">
function ajaxCall() {
var UserName = $("#<%=lblUsername.ClientID %>").text();
$("#passwordAvailable").show();
$.ajax({
type: "POST",
url: 'webServiceDemo.asmx/CheckOldPassword',
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify({ UserName: UserName }),
success: function (data) {
if (JSON.parse(data.d) != "success") // Why we need to use "data.d" ??
{
$("#passwordAvailable").attr("src", "App_Themes/NewTheme/images/deleteICN.gif");
$("#<%=txtOldPwd.ClientID %>").css({ 'border': '1px solid red' });
}
else {
$("#passwordAvailable").attr("src", "App_Themes/NewTheme/images/signoff.gif");
}
}
});
}
</script>
So my Question is why do we need to use data.d
? Why does all data is being stored in .d
and what is .d
?
Because when I use only data
it's not giving me correct return values but when I used data.d
it does.
please give me suggestions.
Server side code C#
[WebMethod]
public string CheckOldPassword(string UserName)
{
// code here
string sRtnValue = "success";
return sRtnValue;
}
so d
is not property or variable but still I got value in .d
Thanks
C# 3.5 and above will serialize all JSON responses into a variable d
.
When the server sends a JSON response it will have a signature similar to this:
{
"d" : {
"variable" : "value"
}
}
With a console.log(data)
inside the ajax success function you'll see the responses data structure in the browser console.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With