2011-12-06 2 views
2

ajax 함수가 성공적으로 수행 된 후 페이지를 새로 고치지 않고 내용을 <div id="container"></div>으로 바꾸고 싶습니다.성공적인 Ajax 함수 후에 div의 내용 바꾸기

$.ajax({ 
     type: "POST", 
     url: "scripts/process.php", 
     data: dataString, 
     success: function() { 
     //Whats the code here to replace content in #conatiner div to: 
     //<p> Your article was successfully added!</p> 
     } 
    }); 
    return false; 

답변

11

http://api.jquery.com/html/

또한
$.ajax({ 
    type: "POST", 
    url: "scripts/process.php", 
    data: dataString, 
    success: function(returnedData) { 
    $('#container').html(returnedData); 
    } 
}); 
http://api.jquery.com/load/

를 사용

$('#container').load('scripts/process.php', { your: 'dataHereAsAnObjectWillMakeItUsePost' }); 
2

그런 다음 success 핸들러에 전달되는 아약스 요청에 대해 "상황"을 설정할 수 있습니다. 여기에서 .html()으로 전화하여 콘텐츠를 대체 할 수 있습니다.

$.ajax({ 
    type: "POST", 
    url: "scripts/process.php", 
    data: dataString, 
    context: '#container', 
    success: function() { 
    $(this).html('<p> Your article was successfully added!</p>'); 
    } 
}); 

참조 :

http://api.jquery.com/jQuery.ajax/
http://api.jquery.com/html/