I have some checkboxes in my web page ,on which i m implementing ajax call,with which i m updating the content in a div and i m refreshing the count of listed items in checkboxes like an ecommerce site filters on sides.But after first checking checkbox first time.ajax call works.But when i check my checkbox again for next time.ajax request is not performed.
Please check the following code
<input type="checkbox" name="item1" id="item1" value="item1">item1[5]<br /> <input type="checkbox" name="item1" id="item2" value="item2">item1[3]<br /> <input type="checkbox" name="item1" id="item3" value="item3">item1[6]<br /> <input type="checkbox" name="item1" id="item4" value="item4">item1[3]<br /> ajax call
$(document).ready(function(){ checkboxValidate = function (e) { if(e)e.preventDefault(); $.ajax({ type: 'get', async:false, cache:false, url: 'getmoredata.php', data: {data1:data1}, success: function(data){ $(data).appendTo('.container'); console.log(data); }, error: function(data){ alert("ajax error occured…"+data); }, timeout:5000 }).done(function(){ //alert(timeout); $("#loading").fadeOut("slow"); $(window).bind("scroll",function(){ scrollMore(); }); }); } } <div id="container"> <div id="div1"> </div> </div> $( "[type=checkbox]" ).change(checkboxValidate); After ajax call the content which i m refreshing
i m executing sql query in getmoredata.php,with which i m getting refreshed checkbox values and their count.
$sql=select DISTINCT colname from tablename where colname='value coming from ajax call' group by colname $sql=select count(colname) from tablename where colname='value from ajax call' group by colname. Then i put the values from first query in an array.second query giving us count so that count i m displaying with each checkbox which is dynamic
then with foreach loop i m refreshing the checkbox contents listed aboved
<?php foreach($arrayquery as $array) { ?> <input type="checkbox" value="<?php echo $array['colname'] ?>"><?php echo $array['colname'] } ?> I m afraid i m not adding the checked in above checkbox line,is it becuase of that my checkbox are not remaining checked... Please have a look once... So after ajax call,whatever data i m getting i m appending in container div,and my checkbox contents are also getting refreshed after ajax call.for example,Initial count of 5 and 3 in first two checkbox items can change to something like 10 or 12 or something else,depending on the data what we got after ajax call.
Now the problem is when i made my first ajax call,and refreshed the divs,after that when i check any checkbox,ajax call is not made,infact nothing happens on page.it remains static as it is. Please check the point and help me on this.clarify if any doubt Thanks in advance
.on()function to bind to dynamic dom elements. EDIT.on()has superseded.live()as suggested by @alexeypalamar