에 난 내 콘솔 (firbug) 내가 얻을에 자바 스크립트 함수기능 내용의 실행 순서
function myfunction() {
var url = location.href;
var ajaxRespose;
$.ajax({
type:"GET",
url: url,
cache:false,
dataType: "text",
success: function(response) {
var data = $.parseJSON(response);
ajaxRespose = data;
console.debug("ajaxRespose ==>:"+ajaxRespose);
}
});
console.debug("first ajaxRespose: " +ajaxRespose);
}
return false;
}
가 없습니다 : 아약스 호출 후 실행 이유
first ajaxRespose: undefined
ajaxRespose ==>:[object Object]
내 질문은의 " 첫 번째 "console.debug. 추신 : 나는 기능을 단순화했습니다. (기능은 정상적으로 작동하지만 문제는 순서대로 실행됩니다.)
'dataType : "text"를 바꿉니다. , with'data type : "json", ' –
이것은 비동기 요청이 작동하는 방식으로, 첫 번째 디버그는 ajax 요청이 완료되기 전에 실행됩니다. – David
가능한 [AJAX 호출에서 응답을 반환하는 방법?] (http://stackoverflow.com/questions/14220321/how-to-return-the-response-from-an-ajax-call) –