0
我很努力地將一個叫做$numbers
的數組傳遞給$.ajax
,就像是1,2,4
那樣。它沒有被識別,我不知道如何在下一頁獲取這些信息。這是我的代碼:
<?php
// $numbers = 1,2,4;
print
"<div class='col-lg-6 col-md-6 col-sm-6 col-xs-12 col-md-pull-6 col-sm-pull-6'>".
"<div class='form-group'>".
"<div class='col-md-12'><strong>Forename:</strong></div>".
"<div class='col-md-12'><input type='text' class='form-control' id='forename'></div>".
"</div>".
"<div class='form-group'>".
"<div class='col-md-12'><strong>Surname:</strong></div>".
"<div class='col-md-12'><input type='text' class='form-control' id='surname'></div>".
"</div>".
"<div class='form-group'>".
"<div class='col-xs-12 col-md-6'>".
"<button id='button' class='btn btn-success btn_add'>Add</button>".
"</div>".
"</div>".
"</div>".
"</div>";
}
?>
<script type="text/javascript">
$(document).on("click", 'button.btn_add', function(){
var forename = document.getElementById('forename').value;
var surname = document.getElementById('surname').value;
var number = <?php echo $numbers; ?>;
if((forename == null || forename == "") && (surname == null || surname == "")){
alert("Please fill in all fields");
}
else {
$.ajax({
url: adduserinfo.php,
method: 'post',
dataType: 'json',
data: 'forename=' + forename + '&surname=' + surname + '&numbers=' + number
});
</script>
'&號碼=」 +數字「缺少等號,如果它真的是一條條ng – devpro
仍然不工作夥伴 –
'$ numbers =「1,2,4」;'也chk yur控制檯 – devpro