[英]GET variable not being sent through AJAX call
我正在嘗試使用AJAX GET方法發送變量,但是無論我做什么都不會發送。 PHP文件始終返回3,這意味着PHP中從未接收到變量q。
<script type="text/javascript">
function myonclickhandler(t) {
var session = " <?php echo ($_SESSION['Username']); ?> ";
if(!(session==null))
{
var val = t.value;
if (t.checked) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
var show = xmlhttp.responseText;
if(show==3)
{
alert(show);
}
}
};
xmlhttp.open("GET", "<?php echo site_url('Buyer_controller/ajax_cart_load?q='); ?>"+ 129, true);
xmlhttp.send();
}
}
}
</script>
Buyer_controller / ajax_cart_load
public function ajax_cart_load()
{
$this->load->helper('form');
$this->load->model("Cart_model", "cartm");
if(isset($_REQUEST["q"]))
{
$check = $_REQUEST["q"];
$result = $this->cartm->populate_cart($check);
$val = $result->value;
$name= $result->Brand." Gift Card";
$quantity= $result->Quantity;
$data2 = array(
'id' => $check,
'qty' => 1,
'price' => $val,
'name' => $name,
'options' => array('Quantity' => $quantity, 'PDID' => $check )
);
if($this->cart->insert($data2))
{
echo 1;
}
else
{
echo 0;
}
}
else
{
echo 3;
}
}
事實證明,在$_REQUEST
中,變量的名稱不是“ q”,而是“ / Buyer_controller / ajax_cart_load?q”。 $_GET
中的變量名稱為“ q”。 因此,我只是在PHP文件中使用了$_GET
而不是$_REQUEST
,它的工作$_REQUEST
很$_REQUEST
。 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.