ajax-product-price.php
Code: Select all
<?php
$currDir = dirname(__FILE__) . '/..';
include("$currDir/defaultLang.php");
include("$currDir/language.php");
include("$currDir/lib.php");
/* grant access to all users who have acess to the order_details table */
$od_from = get_sql_from('order_details');
if(!$od_from){
header('HTTP/1.0 401 Unauthorized');
exit;
}
$pid = intval($_REQUEST['pid']);
$data['UnitPrice'] = sqlValue("select UnitPrice from products where ProductID='{$pid}'");
$data['Quantity'] = sqlValue("select QuantityPerUnit from products where ProductID='{$pid}'");
@header('Content-Type: application/json');
echo json_encode($data);
?>
Code: Select all
$j(function(){
/* on changing product, retrieve unit price from products table and populate unit price field */
$j('#ProductID-container').on('change', function(){
var pid = $j('#ProductID').val();
if(pid == '{empty_value}'){
$j('#UnitPrice').val('');
}else{
$j.ajax({
url: 'hooks/ajax-product-price.php',
data: { pid: pid },
success: function(data){
$j('#UnitPrice').val(data.UnitPrice);
$j('#Quantity').val(data.Quantity);
}
});
}
});
})
Any ideas how to fix this please?