I developed a shopping cart using jquery, ajax and json. It is working fine on local server in chrome. But when I run on server using chrome it is not doing anything; but running on firefox.
It is not running first time, but when I came back from another page then it runs. http://www.scsprojectreports.com/product/coffee-berry-borer.php
JS CODE
function add_to_cart(cart_qty, cart_itemid) {
if (cart_qty <= 0 || isNaN(cart_qty)) {
my_msg('Error', 'Incorrect Quantity');
} else {
$.ajax({
type: "POST",
url: "shopping_cart.php",
data: "cart_itemid=" + cart_itemid + "&cart_qty=" + cart_qty,
success: function (json) {
$("#shopping_cart").html('');
var sub_total = 0;
$.each($.parseJSON(json), function (idx, obj) {
// alert(obj.product_name);
$("#shopping_cart").append(
'<div class="w50">' + obj.qty + ' x </div>' +
'<div class="link"><a href="sub-category-detail-view.html">' + obj.product_name + '</a></div>' +
'<div style="clear:both"></div>');
sub_total += (obj.price * obj.qty);
// alert(sub_total);
});
$("#sub_total").html('Sub-Total: Rs. ' + sub_total);
my_msg('Notification', 'Cart Updated Successfully !!');
$("#msg").html('');
},
beforeSend: function () {
$("#msg").html('<img src="loading.gif" align="absmiddle" alt="Loading...">');
}
});
}
}
PHP CODE
<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;">Qty:
<input type="text" name="qty" id="qty" size="3" value="1">
<a class="button" style="cursor:pointer;" onClick="add_to_cart($('#qty').val(),'<?php echo $fetchline['id'];?>')"><span>Buy</span></a>
<span id="msg" style="text-align:center; padding:6px; color:#EB679F; font-weight:bold; font-size:14px;"></span>
<br>
</div>
Try Using start Google Chrome with Disable web security. If You are using windows 7 then start Command Prompt as Administrator (Right Click On CMD and Select Run as Administrator) and Paste Following Code
C:\Users\admin\AppData\Local\Google\Chrome\Application\chrome.exe --disable-web-security
Here If your chrome installation path is different, then Change path as with your.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.