Issues with ajax when using AppGini 5.81
Posted: 2020-02-06 00:36
I used to have the following code working with version 5.51 but it stopped when switched to 5.81, can't figure why. Using northwind application I have two hooks files:
ajax-product-price.php
order_details-dv.js
It's supposed to return two values for Orders Items table, that is you select the first item (Alice Mutton) the function should populate '39.00' for unit price and '20 - 1 kg tins' for quantity based on northwind's database, and that works perfectly when the application is posted using version 5.51. But it doesn't pull these fields right when the application is posted using version 5.81, instead it pulls the fields of the item that was selected before (if any)
Any ideas how to fix this please?
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?