I have the following input box in PHP while loop:
echo '<ul>';
while ( $data = $supplier->result->fetch_assoc()) {
$sid = (int) $data['sid'];
$supplierName = output($data['supplierName']);
$vid = output($data['vid']);
echo "
<li>
<input type='checkbox' name='sid[]' data-sid='$sid' value='{$sid}|$vid' class='supplierClass'> $supplierName
<div class='allVehicle'></div>
</li>
";
}
echo '</ul>';
Now when I click on a checkbox it's calling another PHP page using jQuery/Ajax, but the result is not showing.
jQuery/Ajax Code:
$('.supplierClass').change(function() {
var sids = [];
$('.supplierClass:checked').each(function(i,v) {
sids.push($(v).val());
});
$.ajax({
url : 'process/get-vehicle.php',
type : 'POST',
dataType : 'html',
data : {
sid : sids,
},
beforeSend : function () {
$(this).next('.allVehicle').html('Please wait...');
},
success : function ( result ) {
$(this).next('.allVehicle').html(result);
}
});
});
I think the problem is on this line but not sure.
beforeSend : function () {
$(this).next('.allVehicle').html('Please wait...');
},
success : function ( result ) {
$(this).next('.allVehicle').html(result);
}
Change it like that, if works!
beforeSend : function () {
$('.allVehicle').next().html('Please wait...');
},
success : function ( result ) {
$('.allVehicle').next().html(result);
//$('.allVehicle').next().text(result); if not workout as html then test it by passing text in it.
}
And if not done then https://api.jquery.com/next/ have a visit here.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.