양식을 제출하면 성공 메시지와 새 ID가있는 새 양식이 반환됩니다. 예를 들어 우편 번호를 입력하여 특정 지역과의 거리를 계산 한 다음 해당 양식을 제출하면 변경 상자가 나타납니다.JQuery가 아약스 양식 제출을 처리하지 않습니다.
$("#PostcodeForm").submit(function (e) {
e.preventDefault();
$('#PostcodeError').text(" ");
$.ajax({
type: "POST",
url: "/Scripts/Scripts.php",
data: {Type:"SavePostcode",Postcode:$('#Postcode').val(),Slug:"<?php if(isset($_GET['ID'])){echo $_GET['ID'];}else{echo "None";}?>"},
success: function(response) {
if(response=="Error"){
$('#PostcodeError').text("That postcode could not be found. Please use the entire postcode and try again.");
}else{
$('#DistanceContent').slideUp("400", function() {
$('#DistanceContent').html(response).slideDown();
});
}
}
});
return false();
});
$("#PostcodeChangeForm").submit(function (e) {
e.preventDefault();
$.ajax({
type: "POST",
url: "/Scripts/Scripts.php",
data: {Type:"ChangePostcode"},
success: function(response) {
$('#DistanceContent').slideUp("400", function() {
$(this).html("Enter your postcode to see how far away this unit is!<br/><form method=\"post\" id=\"PostcodeForm\">Postcode: <input type=\"text\" name=\"Postcode\" id=\"Postcode\" maxlength=\"8\" /><input type=\"submit\" name=\"PostcodeSubmit\" id=\"PostcodeSubmit\" value=\"Calculate!\" /></form><span id=\"PostcodeError\"></span>").slideDown();
});
}
});
return false();
});
처음 제출 내에 응답은 다음과 같습니다
"6 miles, as the crow flies, from POSTCODE.<br/><form method=\"post\" id=\"PostcodeChangeForm\"><input type=\"submit\" name=\"PostcodeChange\" id=\"PostcodeChange\" value=\"Change the Postcode!\" /></form>
내 원래의 HTML 코드는 다음과 같습니다 당신은 Ajax 응답 후 두 번째 양식을 추가
<div class="Widget DistanceWidget">
<span class="Title">Distance:</span>
<span class="Content" id="DistanceContent">
Enter your postcode to see how far away this unit is!<br/>
<form method="post" id="PostcodeForm">
Postcode: <input type="text" name="Postcode" id="Postcode" maxlength="8" />
<input type="submit" name="PostcodeSubmit" id="PostcodeSubmit" value="Calculate!" />
</form>
<span id="PostcodeError"></span>
</span>
</div>
가 뭐죠이') (false를 반환;'? 그것을 제거하십시오 당신은 이미'e.preventDefault();를 호출하는 윈도우 기본 동작을 막고 있습니다 –
무엇이 문제입니까? 어떤 표시가 잘못 되었습니까? 만약 당신이 * 추측한다면, 나는 당신이 두 번째 폼에'submit' 핸들러를 묶어 두지 않을 것이라고 매우 의심합니다. 페이지가로드 될 때 핸들러를 한 번 바인딩하려고 시도하지만 사용자 상호 작용 이후까지 해당 요소가 존재하지 않는 것 같습니다. – David
'return false()'는 이벤트가 발생하지 않도록하는 가장 효과적인 방법입니까? 전혀 모든 것을 방지하십시오. – dfsq