[英]Unable to make a POST with ajax and JSON
I am trying to make a POST with AJAX, but it doesn't recognize the parameters, it just does an empty POST... 我正在尝试使用AJAX进行POST,但是它无法识别参数,它只是执行一个空的POST ...
Here is my ajax code : 这是我的ajax代码:
<script>
$(document).ready(function() {
$('.reserve-button').click(function(){
$.ajax({
type: "POST",
dataType: "json",
url : "generator/",
data : {id: <?=$id?>},
success : function(){
alert("Please give this code to your patient:" );
},
error:function(){
alert("Erreur!!");
}
});
return false;
});
});
</script>
The HTML part : HTML部分:
<div class= "obutton feature2" data-id="<?php echo $id;?>">
<button class="reserve-button">Reserve Book</button>
</div>
Thank you!! 谢谢!!
Your 你的
{id: <?=$id?>}
isn't valid JS. 不是有效的JS。 First try with a hardcoded id, like
首先尝试使用硬编码的ID,例如
{ id: 1234 }
and if that works, then figure out why your templating code isn't correctly generating your id. 如果可行,那么找出为什么您的模板代码无法正确生成您的ID。 : )
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.