0

newbie here. I have a weird issue here where I two functions in my script. Here is the first function:

$(document).on("click", "#result2 p", function(){
        var inv_id = $(this).text();

        $.get("autocomplete_inv.php", {term: inv_id}).done(function(data){
            var inv_info = jQuery.parseJSON(data);

            $('#prod_id_'+id).val(inv_info[0]);
            $('#prod_type_'+id).val(inv_info[1]);
            $('#prod_colour_'+id).val(inv_info[2]);
            $('#prod_price_'+id).val(inv_info[3]);

            console.log('Have Data Here:',$('#prod_price_1').val());

        });

        $('#result2').empty();

        sumPrice();
    }); 

And here is the second function:

function sumPrice(){
console.log('No Data here:',$('#prod_price_1').val());}

The problem is, the output console.log('Have Data Here:',$('#prod_price_1').val()); only shows is the first function and not the second function. I still can't figure out what's the issue here!

Here is the screenshot: Screenshot

Can anyone helps me on this matter? I've been stuck at this part for almost a week. I would sincerely appreciate your answer(s) very much!

Crazy Fox
  • 21
  • 7

1 Answers1

0

Its because ajax request is already running when the control reaches sumprice function. You should write your function inside ajax.done itself.

shreyas d
  • 717
  • 4
  • 14