Jump to content

Calling a php function from JQuery and wait for the response.


Recommended Posts

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.