Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is because you are doing two ajax calls and the second if statement is being hit before the value of a is changed. How the code will be read is:</p> <pre><code>var a = "1"; if ($("#maintable tbody tr").length&gt;0){ //some code here it goes through in order until: $.ajax({ //do this in the background, meanwhile keep executing the code on the page. }); } a is still 1 because results have not come back yet from previous ajax call. if(a =='1'){ $.ajax({ //now do this }); } </code></pre> <p>What you want to do is nest that second ajax call in the success of the first, e.g.:</p> <pre><code>$.ajax({ type: "POST", url: "../model/check_procurement_resold_with_invoice_number.php", data: { para : "upd", invno : invoice, product : prodid, date : vouchdt, quantity : quantity}, success: function(result){ if(result ==1){ a = "1"; $.ajax({ type: "POST", url: "../model/bulk_procurement_resold_at_lowprice.php", data: {action:'updatedb',ud:udata,ad:adata,dd:del_query,username:'&lt;?=$gotuser?&gt;'}, success: function(result){ results = JSON.parse(result); alert('Number of records Updated : '+results['utotal_s']+"\nNumber Of records Inserted : "+results['acnt']+"\nNumber of records Deleted : "+results['dcnt']); // window.location.href="bulk_procurement_resold_at_lowprice.php?vendorinfo="+vendorid+"&amp;dateinfo="+$("#dateinfo").val()+"&amp;catinfo="+$("#catinfo").val(); } }); } else { if(result == "") { alert(productname+" does not exist for invoice number "+invoice); a = "0"; return false } if(result == "2") { alert("Quantity "+ quantity +" for "+productname+" can't be greater than the quantity procured for invoice number "+invoice+" 1"); a = "0"; return false; } } } }); </code></pre> <p>And you'll need to move the <code>if (prodid != 'NA' &amp;&amp; muc != '' &amp;&amp; amt &gt; 0 &amp;&amp; rid != '')</code> function above the ajax call as well. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload