Freonの答えはおそらくうまくdataType
いきます.JSONへの強制を試してみてください.
// This is the signature for $.post
jQuery.post( url [, data] [, success(data, textStatus, jqXHR)] [, dataType] )
$.post("api/authenticate", {"authkey": authkey}, function(data){
console.log(data);
if (data.success === "false") {
window.location="/Login.html";
}
}, "json");
探すべきもう 1 つの考えは、サーバーが 2xx ステータスで応答することを確認することです。別のステータスを返した場合jQuery
、応答を読み取ろうとしません。代わりに、 http://api.jquery.com/jQuery.ajax/statusCode
に渡されるオプションで設定されたステータス コード ハンドラーを探します。
例
jQuery.ajax( "api/authenticate", {
data: {"authkey": authkey},
dataType: 'json',
statusCode: {
306: function(jqXhr, errorType) {
alert('Could not login')
// If you still want to access the response, it's accessible as raw text
// If it's JSON, you have to parse it.
alert (jqXhr.responseText);
}
}
});