Adamhumbug Posted September 12, 2023 Share Posted September 12, 2023 Hi, I have a quote system where you can select and item and give a quantity. This will then go to the database and work out how much the item is per unit. I have the database structure and the code to get the info back. My issue is i need the javascript function that is handling the page being updated to wait for the response from Ajax before updating the page. It all starts here: $(document).ready(function() { updateFormNewQuoteItemChange() ..... } This is called function updateFormNewQuoteItemChange() { $isConsumable = $('#itemId').find(':selected ').data('isconsumable') $quantity = $('#quantity').val() $chargeBy = $('#itemId').find(':selected').data('chargeby') if($isConsumable == 1 && $quantity.length !== 0){ $iid = $('#itemId').find(':selected').val() getConsumablePrices($iid, $quantity); } if ($('#currency').length) { $ccode = $('#currency').find(':selected').data('currency-code').toLowerCase(); $price = $('#itemId').find(':selected').data($ccode) $('#pricePerItem').val($price) $('#pricePerItemDisplay').val($price) } .... } If the item is consumable and has break points this is called function getConsumablePrices($itemId, $qty) { $.ajax({ type: 'post', data: { "ajax": 'getConsumablePriceByQty', 'itemId': $itemId, 'quantity': $qty }, dataType: 'json', success: function(resp) { console.log(resp[0]['CAD']) } }) } This function returns pricing information which comes from a different table than other pricing. I need to feed the result of this AJAX back into the function that it was called from and i think it need it to run synchronously. Any advice, help on this would be really appreciated. Any further information needed, please do ask. Quote Link to comment https://forums.phpfreaks.com/topic/317279-calling-a-php-function-from-jquery-and-wait-for-the-response/ Share on other sites More sharing options...
Adamhumbug Posted September 12, 2023 Author Share Posted September 12, 2023 I cant edit for some reason. The first code block should be $('#currency, #itemId, #startDate, #endDate, #quantity').change(updateFormNewQuoteItemChange) Quote Link to comment https://forums.phpfreaks.com/topic/317279-calling-a-php-function-from-jquery-and-wait-for-the-response/#findComment-1611770 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.