$.ajax() 呼び出しで Web サービスを呼び出すと期待されるデータが返され、$.post() 呼び出しで同じサービスを呼び出すと返されるデータが「未定義」である理由を誰かが理解してくれますか?
Google のツール (.post() 呼び出し用) を使用して Response を調べている間、サーバーから送り返されたデータを確認できますが、どういうわけか .post() 呼び出しの .done() 関数では使用できないことに注意してください。
プログラムはエラーなしで完了します。
コード全体は次のとおりです。
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test01</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(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 + "</br>Status: " + status);
})
.fail(function () { alert("error"); })
.always(function () { alert("completed"); });
});
});
</script>
</head>
<body>
<div id="div01">Here comes the result</div>
<button id="btn01">Load Data with $.ajax : </button>
<button id="btn02">Load Data with $.post : </button>
<input id="KenID" value="11" />
</body>
</html>
ありがとうございました、
ヤセク