[英]How to load all the data at once when select multiple check boxes - Jquery AJAX
I have AJAX
load country city list as below screen shot. 我有
AJAX
加载国家/地区城市列表,如以下屏幕截图所示。 When continent is checked it will load it countries from the database. 选中大洲后,它将从数据库中加载国家。
Here when checked another continent it will load that related countries. 在这里检查另一个大陆时,它将加载该相关国家。 But I want to keep both country list and show all countries.
但是我想保留两个国家/地区列表并显示所有国家/地区。
My current js code is 我当前的js代码是
$("#continent input[type='checkbox']").click(function() {
if($(this).is(':checked')) {
var checked = $(this).val();
var type = 'country';
//alert(checked);
$.ajax({
type: "POST",
url: '<?php echo JURI::root(); ?>index.php?option=com_ajaxwork',
data: {country : checked, type :type},
beforeSend: function() {
$('#countries').html("<img src='/images/loading.gif' />");
},
success: function(e) {
$('#countries').html(e);
},
error: function() {
alert('it broke');
},
complete: function() {
// alert('it completed');
}
});
}
});
And php
code is 和
php
代码是
$countinent_id = $_POST['country'];
$query2 = "SELECT * FROM #__my_country WHERE continent_id = $countinent_id";
$db2 =& JFactory::getDBO();
$db2->setQuery($query2);
$rows2 = $db2->loadObjectList();
foreach ($rows2 as $value) {
print('
<fieldset class="loc_field">
<label>'.$value->country_name .'</label>
<input type="checkbox" name="jform[supplier_country_covered]['.$value->country_id.']" value="'.$value->country_id.'">
</fieldset>
');
}
How do I load all countries at once when checked multiple check boxes at first column. 在第一列中选中多个复选框后,如何一次加载所有国家/地区。
Thanks. 谢谢。
You can try adding continent id as a class to fieldset in your php code. 您可以尝试将大洲ID作为类添加到php代码中的fieldset中。 Then change your jQuery code to
然后将您的jQuery代码更改为
$("#continent input[type='checkbox']").click(function () {
if ($(this).is(':checked')) {
var checked = $(this).val();
var type = 'country';
//alert(checked);
$.ajax({
type: "POST",
url: '<?php echo JURI::root(); ?>index.php?option=com_ajaxwork',
data: { country: checked, type: type },
beforeSend: function () {
//you have to show this some other way
// $('#countries').html("<img src='/images/loading.gif' />");
},
success: function (e) {
$('#countries').append(e);
},
error: function () {
alert('it broke');
},
complete: function () {
// alert('it completed');
}
});
}
else {
var checked = $(this).val();
$('.' + checked).remove();
}
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.