this earlier thread에서 양식 데이터가 POST 메서드를 사용하여 javascript submit() 명령을 사용하여 보낼 수 있다고 생각했습니다. 그러나 나는 그것을 작동시킬 수 없다. 이 데모는 목적과 관련하여 분명한 의미는 없지만 나와 함께 견뎌야합니다. 나는 단지 나를 위해 작동하지 않는이 특정 명령을 테스트하고 싶었어. 저를 도와주세요? 일반 제출 버튼을 클릭하면 게시물 데이터가 제대로 전송되지만 링크를 통해 자바 스크립트를 활성화하는 것은 아닙니다.
javascript submit() 명령이 내 게시물 데이터를 보내지 않습니다.
<html><body>
<?php
$self = $_SERVER['PHP_SELF'];
$posttext = file_get_contents('php://input');
echo "Received input: ".chr(34).$posttext.chr(34)."<br><br>";
echo "<form id='test' action='{$self}' method='post'>";
?>
Please fill in the fields with any text:<br><br>
foo: <input type="text" name="foofield"><br><br>
bar: <input type="text" name="barfield"><br><br>
<input type="submit" value="Submit button works"><br><br>
<a href="" id="submitlink">Submitting by JS not working – why?</a>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
jQuery(function($) {
$(document).ready(function(){
$("a#submitlink").click(function(){
alert("Yes, the link has been clicked. It is not that.");
$("form#test").submit();
});
});
});
</script>
</body></html>
예. 고맙습니다. 모든 일반적인 노력은 submit() 명령과 여기에 문제가되지 않은 구문에 초점을 맞추 었습니다. – danbae