가능한 복제를 작동하지 않습니다
jQuery: Return data after ajax call successJQuery와 함수 반환은
내가 다른 함수에서 호출되어 다음과 같은 기능을 가지고있다. 함수가 작동하는지 여부를 확인하려면 무언가를 반환해야합니다.
//Function to close any existing connection
function closeConnection(manual) {
//Establish connection to php script
$.ajax({
type: 'POST',
url: 'action/chat/closeconnection.php',
success: function (feedback) {
//If this function was called manually, also empty chatTextDiv and fade out chatDiv
if (manual == true) {
//Stop getting messages
clearInterval(setintervalid);
//Fade out chatDiv
$('#chatDiv').fadeOut(100);
//Empty chatTextDiv
$('#chatTextDiv').html('');
//Fade in openChatDiv
$('#openChatDiv').fadeIn(100);
}
}
}).error(function() {
//Append with connection error - user doesn't know that he is disconnected first so it is better to say this as the function will return false and stop other functions
if (manual != true) {
$('#chatTextDiv').append('You could not be connected. Please try again later.<hr/>');
//Stop getting messages
clearInterval(setintervalid);
var closeconnectionsuccess = false;
}
elseif(manual == true) {
$('#chatTextDiv').append('You could not be disconnected. Please try again later.<hr/>');
var closeconnectionsuccess = true;
}
});
return closeconnectionsuccess;
}
실제로 함수의 성공을 반환하려는 마지막 행에 관한 것입니다. 코드가 작동하지 않습니다. 왜 안돼?
을 모두 함께 지금 : 당신은 비동기 함수 값을 반환 할 수 없습니다. – Blazemonger
구문 오류가 있습니다. 'elseif (manual == true) // "else if"와 공백이 있습니다. – elclanrs