Doubt on behavior $ .post and $ .ajax

6

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?

    
asked by anonymous 28.08.2017 / 20:16

1 answer

1

The post method accepts 4 parameters, according to the documentation .

jQuery.post( url [, data ] [, success ] [, dataType ] )

So, you can make the same call by setting the data type sent as json like this:

$.post('XmlTree.aspx/GetChildren', { id : 'S1000' }, 
    function (msg) { ... }, 
    'json'
);
    
26.09.2017 / 20:17