This is my AJAX code:
{
var temp = { ugh: "Yea" };
var value = JSON.stringify({ hash: JSON.stringify(temp) });$.ajax({
type: 'POST',
url: 'BackgroundService.asmx/HandleData',
contentType: 'application/json',
data: value,
success: function(result) {
console.log(result);
},
error: function(error) {
console.log("Error: " + error);
}
});
}
This is my [WebMethod]:
[WebMethod]
public string HandleData(string hash) {
return "Hello world";
}
And this is the result I get when the AJAX succeeds:
Object {d: "Hello world"}
About this "d" __type, I have already looked online for solutions on removing this. As it turns out, most of the solutions didn't worked, and there are other solutions that either requires me to use a 3rd party library, or doesn't apply to me (dynamic linked libraries, etc.).
So, I've decided to keep the "d" __type with me.
Right now, I have no idea how to remove the d. I'm willing to try other methods of removing the d. If you have ideas, please let me know.
Now, I want to know if hard-coding the returned JSON data with the "d" __type is acceptable. Since, inevitably, that d is always going to be there, might as well just write it into the code. Saves a lot of hassle during times when I have work constraints I need to reach.
Is it okay to hard-code the d in my code when I want to access the value of d in the returned JSON data?