Note that there are some explanatory texts on larger screens.

plurals
  1. PO$.ajax() call returns data but $.post() returns "undefined"
    text
    copied!<p>Could someone help me figure out why when I call a web service with $.ajax() call it returns expected data, and when I call the same service with $.post() call, returned data is "undefined"? </p> <p>Please note that while inspecting Response with google's tool (for the .post() call) I can see the data sent back from server but somehow it is unavailable to the .done() function of the .post() call. </p> <p>Program completes without errors.</p> <p>Here is the whole code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Test01&lt;/title&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt; $(document).ready(function () { $("#btn01").click(function () { //.ajax type call $.ajax({ type: "POST", url: "WebService1.asmx/GetData", data: "{KenID:'11'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { $("#div01").html(data.d); } }); }); $("#btn02").click(function () { // .post() type call $.post("WebService1.asmx/GetData", { KenID: "11" }) .done(function (data, status) { $("#div01").html("Data: " + data.d + "&lt;/br&gt;Status: " + status); }) .fail(function () { alert("error"); }) .always(function () { alert("completed"); }); }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="div01"&gt;Here comes the result&lt;/div&gt; &lt;button id="btn01"&gt;Load Data with $.ajax : &lt;/button&gt; &lt;button id="btn02"&gt;Load Data with $.post : &lt;/button&gt; &lt;input id="KenID" value="11" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Thank you,</p> <p>Jacek</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload