내가 이것에 대해 많은 글을 통해 갔다 .post,하지만 나를 위해 일하는 어떤 해결책을 찾기 didnt는 - 코드 정리 :캔트 액세스 변수는
$('#form-new').submit(function(e){
e.preventDefault();
$curForm = $(this);
$textbox = $('.new-box' ,this);
window.tmp_input_ok = false;
var wasError = false;
if($.trim($textbox.val()) == ""){
wasError = true;
}
if(wasError){
//possible message
} else{
var jqxhr = $.post(
$(this).attr('action'),
$(this).serialize(),
function(data, textStatus, jqXHR){
if(data=="200"){
console.log('post OK'); //this shows in console!
window.tmp_input_ok = true;
} else{
console.log('not OK');
}
}
).fail(function() {
console.log('POST fail)');
});
}
//however, window.tmp_input_ok is false here so the textbox does not empty:
if(window.tmp_input_ok == true) $textbox.val('');
else console.log('input not ok :('); //and this is outputted to console
});
Originaly, 단지 var tmp_input_ok = false
초기화 한 후 작업이 있었다 tmp_input_ok
변수가 있지만 작동하지 않아서 글로벌 창을 시도했지만 ... 작동하지 않습니다 ... 필사적이기 시작했습니다.
'$ .post()'호출은 비동기식입니다. 이 함수는 즉시 반환하지만 전달한 콜백은 HTTP 응답을받을 때까지 호출되지 않습니다. – Pointy