페이지가로드 될 때 div가 display : none 인 시나리오가 있습니다. 그리고 버튼 -A를 누르면 div가 토글됩니다. 이 div는 최종 사용자가 데이터베이스에 대해 검색을 수행 할 수있는 검색 창으로 사용됩니다. 그러나 div가 표시되기 때문에 : none; 검색 div 창에서 양식을 제출하면 페이지가 다시로드되고 검색 div 창이 표시되는 곳으로 돌아갑니다. none :페이지 새로 고침없이 양식 제출
그래서 데이터 호출이 실제로 실행되어 필요한 행을 반환합니다. 하지만 결과가 포함 된 div를 표시하려면 버튼 -A를 다시 눌러야합니다.
이 문제를 해결할 수 있습니까? 아약스에 대해 조금 읽었지만 내 경우에는 실제로 해결책을 찾지 못했습니다.
나는 이와 같은 것을 가지고있다. (게시물에 좋은 형식을 모르고 죄송합니다. 그것의 나의 처음 여기에 게시합니다.)
<button id="hideshow" class="hideshow" type="submit">search</button>
<div class="search_div_wrapper" style="display: none;">
<form action="" method="POST">
<input type="text" name="search_field">
<button name="search" id="submit">search</button>
</form>
<?php
// some codes are here to query and display rows from search_field input
?>
</div>
<script>
jQuery(document).ready(function(){
jQuery('.hideshow').on('click', function(event) {
jQuery('#search_div_window').toggle('show');
});
});
</script>
가능한 중복 http://stackoverflow.com/questions/23507608/이 추가 form-submission-without-page-refresh) – Rajesh
"submit"이벤트를 바인드하고 http://api.jquery.com/jquery.ajax/를 사용하십시오. event.preventDefault()를 사용하여 제출을 방지하십시오. – MakG
검색 후 일부 데이터가 제출되었는지 확인하고 디스플레이 none을 표시 블록 정도로 변경하는 것은 어떻습니까? –