次の js スニペットがあります。
<script language="javascript">
function test() {
this.a = 10;
};
test.prototype.next = function () {
alert('before: ' + this.a);
$.ajax({
url: 'some-url',
async: true,
type: 'POST',
dataType: 'json',
success: this.callback
});
};
test.prototype.callback = function () {
alert('after: ' + this.a);
};
$(document).ready(function () {
var test1 = new test();
test1.next();
});
</script>
それは常に結果を生成します: before: 10 after: undefine.
$.post のコールバック関数で、class のプロパティが定義されていないのはなぜですか。誰でも私を助けることができますか?どうもありがとう。