我有一个简单的选择,它通过 ajax 更改发布数据。在同一页面上,我想从 POST 数组中获取数据,但后数组为空。这是代码。
Javascript
$('.product-selectbox').change(function() {
var select_id = $(this).attr("id");
var presentkort_type = $(this).val();
presentkort_type = presentkort_type;
alert(presentkort_type);
//alert("id is "+id);
var request = $.ajax({
url : "cashregister",
type : "POST",
data : {
prod_id : select_id, presenkort : presentkort_type
},
dataType : "html"
});
request.done(function(msg) {
$('#data').html(select_id);
console.log(select_id);
console.log(presentkort_type);
location.reload(true);
});
request.fail(function(msg) {});
});
PHP
if (isset($_POST['prod_id'])) {
$product_id = (int)$_POST['prod_id'];
print "product id is ".$product_id;
} else {
print "no data";
$product_id = (int)$_POST['prod_id'];
}