I've always been accustomed to using $.ajax()
for all my type requests, and this works perfectly. An example that is even occurring now is the following:
$.ajax({
type: "POST",
url: "XmlTree.aspx/GetChildren",
data: {id : teste},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
if (callback) {
callback(msg);
}
},
error: function (msg) {
if (callback){
callback(msg);
}
}
});
Calling like this, it falls into the method I intended. Everything works fine, as the image below shows:
However, I read about $.post
and its syntax seemed to me much much simpler , and I decided to test it as follows:
$.post( "XmlTree.aspx/GetChildren", { id : "S1000" } );
The problem is that regardless of my parameters, using $.post
it always drops in Page_Load, as the image shows:
Iamawareoftheexistenceofthisquestion: What are the advantages of using the correct HTTP methods? .
But I still could not understand the reason for this behavior. Should not $.post
fall directly into my GetChildren
method?