그래, 다른 포럼을 둘러 보았고, 왜 내 것이 아직도 ... GAH인지 알 수 없습니다. 양식이 제출하지 않도록 preventDefault()를 호출합니다. 나는 아무 것도 설정하지 않은 후 폼 태그에 액션 속성을 전혀 제공하지 않았다.Jquery preventDefault가 작동하지 않습니다.
제출 버튼을 제출 대신 버튼으로 시도했지만 여전히 작동하지 않는 것 같습니다. 양식은 제출할 때 페이지를로드하는 중입니다. 나는 AJAX로 사용자 샵에서 아이템의 가격을 업데이트하려고 노력하고 있으므로 span 태그의 페이지를 다시로드하지 않고도 가격을 업데이트합니다.
는 HTML:
<form id="price_form" method="POST" action="http://alkharia.localhost/user/shop/priceitem/3" accept-charset="UTF-8"><input type="hidden" name="csrf_token" value="P0oW2VxJ6HTg79ksIYl6U3R5QKapeFGwkkUKiNlQ">
<div class="row clearfix">
<div class="full">
<label for="price">Price</label>
<input maxlength="6" type="text" name="price" value="0" id="price"> </div>
</div>
<div class="row">
<div class="full">
<input type="hidden" name="item_id" value="3">
<input type="submit" value="Submit"> </div>
</div>
</form>
JQuery와 :
$('#price_form').submit(function(e) {
e.preventDefault();
var price = $('#price').val();
if((Math.floor(price) == price) && ($.isNumeric(price)) && (price.length <= 6)) {
var itemID = $('#item_id').val();
$.ajax({
type: 'POST',
url: 'http://'+urlBase+'/user/shop/priceit/'+itemID+'/'+price,
success: function(msg) {
$('#cur_price_'+itemID).html(msg);
}
});
} else {
alert('You can only enter an integer that is less than 999,999!');
return false;
}
});
JS 콘솔에서 오류가 있는지 확인하십시오. 코드가 작동해야합니다. – Blender
http://stackoverflow.com/questions/6462143/prevent-default-on-form-submit-jquery 및 프록시 : http://stackoverflow.com/questions/1357118/event-preventdefault-vs-return-false –
나는 그것이 효과가있을 것이라고 생각 하겠지만 AJAX가 제공 한 url이나 form action 속성에 의해 유도된다. 그래서 다른 모든 로직을 수행하는 대신 제출 한 후에 해당 페이지로 로딩됩니다. :/ – Peanut