신체 내부에 컨테이너를 사용하고 코드를 신체에 직접 놓아 두지 마십시오.
즉. JS 호출
$('.container').html(response).show('slow');
본문에 내용이로드 컨테이너와 직접적으로 모두 대체 할 그 길에 그런 용기
<div class="container"></div>
될 것입니다 신체 내부의 div 태그에 추가 당신이 가지고있는 JS를 포함한 페이지의 내용.
또한 Ajax 호출을 사용할 때 더 깨끗한 코드가 처리 할 다른 함수에 대한 응답을 전달한다고 생각합니다. 그렇게하면 디버그하고 코드를 더 쉽게 이해할 수있는 작은 함수가 생깁니다.
$.ajax({
url: 'ajax/test.html',
success: function(data) {
//Here you pass the response to the other function
processSuccess(data);
},
fail: function(data) {
//Here you pass the response to the other function
processFail(data);
}
});
function processSuccess(response) {
//Print the response in the console (ie. Firebug console)
//if console is available
if(console) {
console.log(response);
}
};
function processFail(response) {
//Print the response in the console (ie. Firebug console)
//if console is available
if(console) {
console.log(response);
}
};
물론 네임 스페이스 안에있는 모든 것이 더 좋습니다.
스크립트가 body 태그 내에있는 경우 html() 메서드는 모든 내용을 지우고 body 요소 대신 다른 요소에 데이터를 추가하는 것을 고려합니다. – undefined
'나는 다음과 같은 자바 스크립트''$ .ajax ({type : ... url : ... data : ... bla bla ...'를 어떻게 실행합니까? – Nope
'javascript 사라지다 '? 페이지가로드됩니까? –