I have a simple ASP.NET web application with the following javascript that runs on an input's onblur event:
function checkUserName() {
var request = new XMLHttpRequest();
if (request == null) {
alert("Unable to create request.");
} else {
var theName = document.getElementById("username").value;
var userName = encodeURIComponent(theName);
var url = "Default.aspx/CheckName?name='" + theName + "'";
request.onreadystatechange = createStateChangeCallback(request);
request.open("GET", url, true);
request.setRequestHeader("Content-Type", "application/json");
request.send();
}
}
The C# method this calls is the following:
[WebMethod]
[ScriptMethod(UseHttpGet = true)]
public static string CheckName(string name)
{
return name + " modified backstage";
}
The javascript callback for the XMLHttpRequest is the following:
function createStateChangeCallback(request) {
return function () {
if (request.readyState == 4) {
var parsed = JSON.parse(request.responseText);
alert(parsed.d);
}
}
}
Although this displays the results of my server-side method, I was wondering about that property "d" I need to access to get the results. I found this only by using Intellisense. Is this property a standard property for accessing the parsed JSON? Should I be going about it some other way? Is "d" arbitrary or is it determined somehow? Is it possible for me to set the name of the property, either client or server -side?