ISSUE :
 
Profile photo
Submitted by Kinnari Patel
on May 2nd, 2014 at 03:15:41 EST

i want call ajax url depend on loop. here we try to alert box to knaw which value get but it get only last value

for(j=0;j<len;j++)
{

$(".product_name").append("<div id='Product_"+j+"'>"+$("#rav").children().eq(j).text()+"</div>");
var content=$("#rav").children().eq(j).text();
var pid=$("#nav").children().eq(j).text();
$.ajax({

url: '<?php echo base_url();?>index.php/dataurl?pid='+pid+'&content='+content,
success:function(r){
var $r = $(r);
// var $page = $r.find('#fk-mainbody-id').html().trim();
alert("pid:"+pid);
alert(j);
}
})

}


Profile photo
Replied by SBajra
on May 2nd, 2014 at 10:15:07 EST
Can you please post your HTML code? Without HTML its hard to say anything about your Javascript.

Profile photo
Replied by Kinnari Patel
on May 3rd, 2014 at 03:53:59 EST
hi, thanks for reply me :)
//this my view file

<script type="text/javascript" src="<?php echo base_url();?>js/jquery-1.10.2.min.js"></script>
<br/>
<h1>Product Name</h1>
<div class="product_name"></div><br/><br/>
<div id="rav"></div>
<div id="nav"></div>
<div id="prod_id"></div>

<script>
var flag=0;
var i=0;
var j=0;
if(flag==0)
{
<?php foreach($list as $lists):?>
var name='<?php echo $lists['title']; ?>';
var purl='<?php echo $lists['purl']; ?>';
var pid='<?php echo $lists['prod_id']; ?>';
$("#rav").append("<div id='Product_"+i+"'>"+name+"</div>");
$("#nav").append("<div id='Purl_"+i+"'>"+purl+"</div>");
$("#prod_id").append("<div id='Pid_"+i+"'>"+pid+"</div>");
i++;
<?php endforeach; ?>
flag=1;
}
if(flag==1)
{
i++;
var len=i-1;
var j=0;
for(j=0;j<len;j++)
{

$(".product_name").append("<div id='Product_"+j+"'>"+$("#rav").children().eq(j).text()+"</div>");
var content=$("#rav").children().eq(j).text();
var purl=$("#nav").children().eq(j).text();
var pid=$("#prod_id").children().eq(j).text();
getdata(content,purl,pid,len,j);

}
}
function getdata(content,purl,pid,len,j)
{
var ex=content.split(',');
var name=ex[0];
$.ajax({
url:"<?php echo base_url();?>index.php/dataurl?url="+purl+"&content="+name,
data:{ajaxRequest:'true'},
success:function(r){
var $r = $(r);
var $page = $r.find('.fk-font-verybig').html();
var price=$page.substr(5);
var ary_pid_price = []; // Array is empty
ary_pid_price.push({prod_id:pid, prod_price:price});
//ary_pid_price.push({pid});
price=ary_pid_price[0].prod_price;
pid=ary_pid_price[0].prod_id;
$.ajax({

url:"<?php echo base_url();?>index.php/fetch/update_price/"+price+"/"+pid,
data:{ajaxRequest:'true'},
success:function(r){
//alert("update successfully");
}
})



}
})
}

</script>

//controller
function update_price($price,$pid)
{
$this->home_model->edit_mobileprice($price,$pid);
// redirect(home);
}

Profile photo
Replied by Yogaraj Khanal
on June 4th, 2014 at 21:32:15 EST
Try using error callback function which will help you isolate that if is it getting any error from back end.

Also use firebug plugin in firefox and you can put break point and step through your javascript jquery code which will help you find your js error easily.
Hope that helps.