任务:当我从select tag customer(我有customer_id)中选择时,它必须得到DB的请求并返回所有客户字段.然后它必须自动填充一些输入.我尝试制作ajax + jQuery.Ajax很好.它现在正在工作!
这是JS:
我弄明白了:
<script>
$(document).ready(function() {
$('#customer_load').change(function() {
$.ajax({
url: '<?= $this->url(array('action' => 'ajax', 'controller' => 'baza')) ?>',
type: 'POST',
dataType: 'json',
data: {
// list of request parameters
'customer_id': $(this).attr('value')
},
success: function(data) {
//alert(data.current_discount);
$('#extra_discount').val(data.extra_discount);
$('#current_discount').val(data.current_discount);
$('#customer_number').val(data.customer_id);
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
PHP初始化:
$this->_helper->AjaxContext()->addActionContext('add', 'json')->initContext('json');
Run Code Online (Sandbox Code Playgroud)
Ajax动作:
$id= $this->_getParam('customer_id');
$result = $this->_customers->fetchSelected($id);
$this->view->customers = $result;
$this->_helper->json($result);
Run Code Online (Sandbox Code Playgroud)
HTML:
<select name="customer_id" id="customer_load" style="width:300px;">
<option value="0">???????? ?????????</option>
?php foreach ($this->customers as $cus): ?>
<option value="<?= $cus['customer_id'] ?>"" <?php if …Run Code Online (Sandbox Code Playgroud) 我有一个AJAX + jQuery示例,成功的我有我的数据数组.对于我在Firebug中的实验,我没有看到太大的区别.哪个更快,for还是each在jQuery中?
for 例:
for (var i = 0; i < data.length; i++) {
options += '<option value="' + data[i].c_id + '">'+ data[i].c_name +'</option>';
}
Run Code Online (Sandbox Code Playgroud)
each 例:
$(data).each(function() {
options += '<option value="' + $(this).attr('c_id') + '">' + $(this).attr('c_name') + '</option>';
});
Run Code Online (Sandbox Code Playgroud) 我需要写出这样的:
6 5 4 3 2
5 4 3 2
4 3 2
3 2
2
Run Code Online (Sandbox Code Playgroud)
我想这肯定是这样的
for ($i = 6; $i > 1; $i--) {
echo $i . " ";
}
Run Code Online (Sandbox Code Playgroud)