javascript - call ajax function onload and on button click -
i want show report base on election date. when call function showreport() on form load working, it's not working when call function on button click.
report members
<script> function showreport(){ var = $('#from').val(); var = $('#to').val(); var str = $('#str').val(); if(from == '' && == '') { var = '$from'; var = '$to'; } $.ajax({ url: "crm_data_report.php?type="+str+"&from="+from+"&to="+to, method: "post", success: function(data) { console.log(data); var date = []; var value = []; for(var in data) { date.push(data[i].date); value.push(data[i].value); } var color = chart.helpers.color; var chartdata = { labels: date, datasets : [ { label: 'members', backgroundcolor: color(window.chartcolors.red).alpha(0.5).rgbstring(), bordercolor: window.chartcolors.red, borderwidth: 1, data: value } ] }; var ctx = $("#mycanvas"); var bargraph = new chart(ctx, { type: 'bar', data: chartdata }); }, error: function(data) { console.log(data); } }); }
the code called function on load , on button click.
<script> $(document).ready(function(){ showreport(); }); $('#filter').click(function(){ showreport(); }); </script>
replace code block this:
$(function(){ $('#filter').click(function(){ showreport(); }); })
its common issue binding click event when button not available dom yet , have bind when dom tree ready.
Comments
Post a Comment