I am using a select box to navigate to a new page but the table div data will be received from another data based on the select box. Here is my code
html page
<select id="works" class="btn btn-default" style="text-align:left; background-color:#FFF" onchange="getboq(this)">
<option value=""> Select Work Name</option>
<option value="1" style="text-align:left"><?= 1 ?>
<option value="2" style="text-align:left"><?= 2 ?>
</option>
</select>
Js file
function getboq(work)
{
var boq = work.value;
$.ajax({
url: 'data/cont_boq.php',
type: 'post',
dataType: 'json',
data: {
boq:boq,
},
success: function (data) {
window.location = 'boq.php'
$('#boq').html(data);
},
error: function(){
alert('error');
}
});
}
Cont.php
Its a normal table based on select box value, How ever even i made a simple table as well to check if it works but my efforts bore no fruit
boq.php
is a simple php page having the required div
<div id="boq"></div>
Interestingly i can see the response on firebug but getting alert "error"
window.locationwhich will change the page to boq.php and refresh, thereby destroying everything you've just done in downloading the other data.boq.phpin the ajax success callback. This will refresh browser and all your AJAX data will be lost. You need to insert the returned table data to DOM on the same page.dataType: 'json',), however the file contains HTML. You should consider using jQuery's.load(). Or change thedataTypetohtml. Or import the file with PHP by usinginclude 'boq.php';