这是我的代码我做了什么
function price() {
var quantity = document.getElementById("quan").value;
var select = document.getElementById("p_id");
var product_id = select.options[select.selectedIndex].value;
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
//alert("working");
document.getElementById("price_ajax").innerHTML = this.responseText;
}
}
xmlhttp.open("GET", "get_product.php?p_id=" + product_id + "&quantity=" + quantity);
xmlhttp.send();
这是我执行ajax请求的php代码:
$p_id = intval($_GET['p_id']);
$quantity = intval($_GET['quantity']);
$connection=new Database();
$sth=$connection->DBH->prepare("SELECT `unit_price` FROM `product_lookup` WHERE `id`=?");
$sth->bindParam(1,$p_id);
$sth->setFetchMode(PDO::FETCH_OBJ);
$rs=$sth->execute();
$row =$sth->fetch();
$product_price= intval($row->unit_price);
$total_price=$product_price*$quantity;
?>
<input value="<?php echo $p_id?>">
这是我的HTML:
<input class="form-control" type="number" name="price[]" id="price_ajax" >
这是我调用javascript函数的地方:
<input class="form-control" type="number" name="quantity[]" id="quan" oninput="price()" required>
这是我的ajax请求不响应的情况