0
다음 mootools 코드는 아무 문제가 없습니다. 내가 뭘하고 싶은지 onsubmit 이벤트와 두 번째 코드 블록에서와 마찬가지로 domready없이 다시 작성하십시오. 감사.Mootools는 domready없이 onsubmit을 처리합니다
<html>
<head>
<title>Simplest Form Ajax</title>
<script type="text/javascript" src="../mootools/mootools-core-1.3.2fc.js"></script>
<script type="text/javascript">
window.addEvent('domready', function() {
$('myForm').addEvent('submit', function(e) {
e.stop();
this.set('send', {
onComplete: function(response) {
$('log_res').set('html', response);
}
});
this.send();
});
});
</script>
</head>
<body>
<h3>Send a Form with Ajax</h3>
<form id="myForm" action="ajaxRes.php" method="post">
<div>
<p>Enter something:
<input type="text" name="something" value="John" />
<input type="submit" />
</p>
</div>
</form></br></br>
<h3>Ajax Response</h3>
<div id="log_res"></div>
</body>
</html>
미완성 코드 :
<html>
<head>
<title>Simplest Form Ajax</title>
<script type="text/javascript" src="../mootools/mootools-core-1.3.2fc.js"></script>
<script type="text/javascript">
function loadMe() {
...
});
</script>
</head>
<body>
<h3>Send a Form with Ajax</h3>
<form id="myForm" action="ajaxRes.php" onsubmit="loadMe()" method="post">
<div>
<p>Enter something:
<input type="text" name="something" value="John" />
<input type="submit" />
</p>
</div>
</form></br></br>
<h3>Ajax Response</h3>
<div id="log_res"></div>
</body>
</html>
왜 두 번째 블록을 선호합니까? 첫 번째는 우아한 솔루션으로 간주됩니다. 눈을 아프면 외부 파일로 이동하십시오. :) –