1
버튼을 누르면 현재 표시된 페이지의 HTML을 다른 파일에 저장하는 프로그램의 일부로 작업하고 있습니다. 내 문제는 몇 초 동안 버튼을 누르는 사이에 일시 중지하지만 버튼을 한 번 이상 빠르게 누르면 파일을 저장하지만 파일의 html이 올바르지 않으면 정상적으로 작동한다는 것입니다. 원래 HTML 컨텐트의 여러 사본을 파일에 저장하는 것처럼 보입니다.html 콘텐츠의 여러 복사본 저장 방지
HTML :
<form method="POST" action="app/savePage.php" id="file-options-form" name="file-options-form">
<!--used to store content before it is saved-->
<input type="hidden" value="" name="content" id="tm-content">
<!--used to store scripts before it is saved-->
<input type="hidden" value="" name="scripts" id="tm-scripts">
<!--used to store styles before it is saved-->
<input type="hidden" value="" name="styles" id="tm-styles">
<span id="file-button-container">
<input type="button" name="new-page-button" value="New Theme" id="new-page-button">
<input type="submit" name="save-button" value="Save Theme" id="save-button">
<label for="theme-name">Theme Name:</label>
<input type="text" value="" name="theme-name" id="theme-name">
</span>
</form>
자바 스크립트/JQuery와 : 아래
내가 사용하고있는 코드입니다$("#file-options-form").submit(function(e){//begin function
//stop form from submitting
e.preventDefault();
//the content to save
var contentToSave = [];
//add the html of the file to the contentToSave array
contentToSave.push($("html")[0].outerHTML);
//store the content in the #tm-content hidden input box
$("#tm-content").val(contentToSave.join(""));
//url for saveTheme.php file
var url = "/thememaker/app/saveTheme.php";
//begin ajax function
$.ajax({//begin ajax function
type:"POST",
url: url,
data:$(this).serialize(),
success:function(data){//begin success function
},//end success function
error:function(e){
alert(e);
}
//todo: fix multiple button press problem
});//end ajax function
});//end function
시도 수정 :
내가 해제 시도 버튼을 클릭하면 차 나는이 내 문제에 대한 진정한 해결책이었다 아약스 성공 기능
서버에 도달하는 첫 번째 스크립트가 세션을 유지하는 한 표준 PHP 세션을 가정하면 다른 스크립트는 아무 것도 할 수 없습니다. PHP는 세션 파일을 잠그고 두 번째, 세 번째 등 ... 스크립트는 잠금이 해제 될 때까지 기다려야합니다. 그렇지 않으면, 자물쇠를 스스로하십시오. 추가 스크립트가 있는지 확인하기 위해 "이미 실행중인"플래그를 어딘가에 두십시오. 깃발이 존재하면 그들은 보석금을 낸다. –
좋은 아이디어, 나는 깃발 제안을 시도 할 것이다. 감사합니다 –
가능한 복제본 [PHP 및 동시 파일 액세스] (0120-556-100)/ – skobaljic