2 Consecutive JQuery Posts, second executed first
Please help me with this...
I have to pass values to a php file for save, but if a check box has been
selected, it has to execute the second jquery post using the return value
from the first. But it seems like the second jquery post is being executed
first, here's my code:
if($action=="save_prod")
{
var remember = document.getElementById('chk');
var $suppid=document.getElementById('supp').value;
var $categlist=document.getElementById('categlist').value;
var $prodname=document.getElementById('prodname').value;
var $proddesc=document.getElementById('proddesc').value;
$.post(baseurl+'index.php/main/newproduct',{"categlist" :
$categlist,"prodname" : $prodname," proddesc" : $proddesc,"supp" :
$suppid},function(response)
{
$lastid=response;
if($lastid != 0)
{
alert("Product has been saved with ID=" + $lastid);
document.getElementById('resp').style.display='none';
document.getElementById('fade').style.display='none';
window.location.href=baseurl
+"index.php/main/mgtprods/?key="+ $suppid;
}
});
if (remember.checked)
{
//alert($lastid);
$.post(baseurl+'index.php/main/newitem',{"prodlist" : $lastid
,"itlist" : 0,"itcost" : 0, "supp" : $suppid, "itname" :
$prodname, "itunit" : "pc" },function(response)
{
document.getElementById('resp').style.display='none';
document.getElementById('fade').style.display='none';
//window.location.href=baseurl
+"index.php/main/mgtprods/?key="+ $suppid;
});
}
}
Thank you so much!
No comments:
Post a Comment