大家好,我试图在已创建的div中显示ajax响应,但我无法显示。你能帮我解决我错在哪里吗?无法在已创建的div标签中显示ajax响应
<form id="coupon" action="">
<label>Have a Coupon?</label>
<input name="couponcode" id="couponcode" value="" />
<input type="submit" value="Apply" />
</form>
<div id="result"></div>
现在我jQuery的功能是下面一个。
$("#coupon").submit(function (event) {
/* Stop form from submitting normally */
event.preventDefault();
/* Clear result div*/
$("#result").html('');
/* Get some values from elements on the page: */
var values = $(this).serialize();
/* Send the data using post and put the results in a div */
$.ajax({
url: "coupon.php",
type: "post",
data: values,
success: function (response) {
$('#result').html(response);
}
});
});
我的coupon.php
文件代码在1以下。
<?php
if (!empty($_POST)) {
$coupon = $_POST['couponcode'];
//json_encode(array('coupon' => $coupon));
echo $coupon;
}
?>
认沽警报,并检查响应为空或返回任何价值 – Gautam3164
'$(“#优惠券”),HTML(。 ..''你不是说'$('#result')。html(...' – blue112
没有什么当我成功提醒 – user2362946