Ajax dont activate php code -
i'm trying remove product session cart.i'm sending request ajax event on click , nothing happens.here code.i don't response,like button @ don't work anything. on button press erase id session data , remove product div.
function removefrombasket(item) { var xmlhttp = new xmlhttprequest(); xmlhttp.onreadystatechange = function() { if (xmlhttp.readystate == 4 && xmlhttp.status == 200) { alert('item removed') } else if(xmlhttp.status == 400) { alert("request error 400"); } else{ alert("something went wrong"); } }; xmlhttp.open("get","cart.php?remove="+item,true); xmlhttp.send(); }
cart.php
<?php require "cfg.php"; if(isset($_get['remove'])){ $id = $_get['remove']; $items = $_session["cart"]; if(($key = array_search($id, $items)) !== false) { unset($items[$key]); $ses = $_session["cart"] = array_values($items); } print_r($ses); die(); } ?> <!doctype html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> <?php $cart = session::get("cart"); $cartitems = array_keys($cart); $q = "select * items id in (".implode(",",$cartitems).")"; $db = database::getinstance(); $res = $db->_db->query($q); foreach($res $item){ ?> <form method="post" action="" class='.remove'> <div style='border:1px solid blue;padding:4px;'> <?=$item['name']?> (<?=$cart[$item['id']]?>) <input class='glyphicon glyphicon-remove' onclick='removefrombasket(<?= $cart[$item['id']] ?>)' name='submit' type='button' value='remove' > </div> <?php } ?>
Comments
Post a Comment