在一个表单中,如何通过ajax传入两个或多个数据,点击控制器
Html代码
<div class="form-group col-md-4">
<input type="hidden" name="valdte" value="<?php echo $todate; ?>">
<label for="">Sort By</label>
<select class="form-control" id="picker">
<option>-----Select--------</option>
<option value="1">Executive</option>
<option value="2">Location</option>
</select>
</div>
<div id="new_in" class="form-group col-md-4"></div>
ajax代码是
<script type="text/javascript">
$(document).ready(function() {
$('#picker').on('change', function() {
var StateID = $(this).val();
console.log(StateID);
if (StateID) {
$.ajax({
type: 'POST',
url: 'sort_by',
data: 'id=' + StateID,
success: function(html) {
$('#new_in').html(html);
}
});
} else {
$('tbody').html('<option value="">Select View by first</option>');
}
});
});
</script>
如何以任何方式将隐藏的字段值传递给这些函数?
答案 0 :(得分:1)
将其用作
<input type="hidden" id="valdte" name="valdte" value="<?php echo $todate; ?>">
<script type="text/javascript">
$(document).ready(function() {
$('#picker').on('change', function() {
var StateID = $(this).val();
var data1_value = $('#valdte').val();
var data2_value = "bcd";
var data3_value = "ety";
console.log(StateID);
if (StateID) {
$.ajax({
type:'POST',
url:'sort_by',
data:{data1:data1_value,data2:data2_value,data3:data3_value,id:StateID},
success:function(html){
$('#new_in').html(html);
}
});
} else {
$('tbody').html('<option value="">Select View by first</option>');
}
});
});
</script>