[英]Why does my button dosen't submit the form using ajax and jquery?
我想了解為什么我的表單沒有提交,但是我不知道為什么。 我試圖console.log數組值的值,它完美地工作。
當我單擊表單的提交按鈕時,它僅顯示警報“確定”並重新加載頁面,但不提交表單...
<form method="POST">
<?php
while($service = $req->fetch()){ ?>
<div class="form-control">
<input type="checkbox" class="getValue" value="<?= $service['price']; ?>">
<label><?= $service['service']; ?></label>
<strong><?= $service['price']; ?>€</strong>
</div>
<?php } ?>
<button type="button" name="submit" class="btn btn-warning" id="submit">Submit</button>
</form>
$(document).ready(function(){
$('#submit').click(function(e){
e.preventDefault(); // annul action par défaut du button
var values = [];
$('.getValue').each(function(){
if($(this).is(":checked")){
values.push($(this).val());
}
});
values = values.toString();
// PROBLEME HERE:
$.ajax({
url:"addServicesRequest.php",
method:"POST",
data:{values:values},
success:function(data){
alert("ok");
}
});
});
});
在此先多謝!
我已經開始工作了! 錯誤是我放了而不是我刪除了e.preventDefault();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.