我的方案是在下拉列表更改时为textField增加值,现在我使用ajax和json并使用cibonfire HMVC框架,这是我的代码。
/* get airline and unit */
$('select[name="item"]').change(function() {
$.ajax({
url: 'reg_inv_penjualan/getAirlineAndUnit',
type:'POST',
data: ({
ci_csrf_token: $("input[name=ci_csrf_token]").val(),
id: $(this).val()
}),
dataType:'json',
success: function(data) {
aData = eval(data);
console.log(aData);
},
error: function(error) {
console.log( JSON.stringify(error) );
}
});
});
这是我返回json使用json_encode的方法;
/**
* method:
* @return: json
*/
function getAirlineAndUnit() {
$this->output->set_header("Content-Type: application/json; charset=utf-8", true);
$id = $this->input->post('id');
$data = $this->reg_inv_penjualan_model->getAirlineAndUnit($id);
die(json_encode($data));
}
这是我的形象:
当下拉列表项目更改时,航空公司文本字段将获得值。
感谢。
返回错误:
{"readyState":4,"responseText":"\r\n<div class=\"row-fluid\">\r\n\t<ul class=\"nav nav-tabs\">\r\n\t\t<li>\r\n\t\t\t<a href=\"http://localhost/stam/admin/invoicing/reg_inv_penjualan/add_item/tiket/reg_inv_penjualan\">Tiket</a>\r\n\t\t</li>\r\n\t\t<li>\r\n\t\t\t<a href=\"http://localhost/stam/admin/invoicing/reg_inv_penjualan/add_item/hotel/reg_inv_penjualan\">Hotel</a>\r\n\t\t</li>\r\n\t\t<li>\r\n\t\t\t<a href=\"http://localhost/stam/admin/invoicing/reg_inv_penjualan/add_item/tour/reg_inv_penjualan\">Tour</a>\r\n\t\t</li>\r\n\t\t<li>\r\n\t\t\t<a href=\"http://localhost/stam/admin/invoicing/reg_inv_penjualan/add_item/dokumen/reg_inv_penjualan\">Dokumen</a>\r\n\t\t</li>\r\n\t\t<li>\r\n\t\t\t<a href=\"http://localhost/stam/admin/invoicing/reg_inv_penjualan/add_item/trans/reg_inv_penjualan\">Transportasi</a>\r\n\t\t</li>\r\n\t\t<li>\r\n\t\t\t<a href=\"http://localhost/stam/admin/invoicing/reg_inv_penjualan/add_item/haji/reg_inv_penjualan\">Haji</a>\r\n\t\t</li>\r\n\t\t<li>\r\n\t\t\t<a href=\"http://localhost/stam/admin/invoicing/reg_inv_penjualan/add_item/umroh/reg_inv_penjualan\">Umroh</a>\r\n\t\t</li>\r\n\t\t<li>\r\n\t\t\t<a href=\"http://localhost/stam/admin/invoicing/reg_inv_penjualan/add_item/other/reg_inv_penjualan\">Other</a>\r\n\t\t</li>\r\n\t</ul>\r\n\t\r\n<div class=\"row-fluid\">\r\n\t<div class=\"pull-right\">\r\n\t\t<button id=\"btnAddTiket\" class=\"btn btn-success pull-righ\" ><i class=\"icon-plus\"></i> Add Item</button>\r\n\t</div>\r\n</div>\r\n\r\n<hr />\r\n\r\n<div class=\"row-fluid\">\r\n\t<table id=\"tblInvItemTiket\" class=\"table table-striped dataTable\">\r\n\t\t<thead>\r\n\t\t\t<tr>\r\n\t\t\t\t<th>No. Booking</th>\r\n\t\t\t\t<th>Maskapai/Airline</th>\r\n\t\t\t\t<th>No. Penerbangan</th>\r\n\t\t\t\t<th>Penumpang</th>\r\n\t\t\t\t<th>Pax Paid</th>\r\n\t\t\t</tr>\r\n\t\t</thead>\r\n\t\t<tbody></tbody>\r\n\t\t<tfoot></tfoot>\r\n\t</table>\r\n</div>\r\n\r\n<!-- Modal -->\r\n<div id=\"myModal\" class=\"modal hide fade\" tabindex=\"-1\" role=\"dialog\" aria-labelledby=\"myModalLabel\" aria-hidden=\"true\" style=\"width:800px;margin-left:-400px;\">\r\n\t<form class=\"form-horizontal cmxform\" id=\"formTiket\" method=\"get\" action=\"\">\r\n\t\n<input type=\"hidden\" name=\"ci_csrf_token\" value=\"c0d97bdcf095acff1bdc7efa1b488efb\" />\n\t<div class=\"modal-header\">\r\n\t\t<button type=\"button\" class=\"close\" data-dismiss=\"modal\" aria-hidden=\"true\">×</button>\r\n\t\t<h3 id=\"myModalLabel\">Add Item</h3>\r\n\t</div>\r\n\t\r\n\t<div class=\"modal-body\">\r\n\t\t<div class=\"admin-box\">\r\n\t\t\r\n\t\t\t<fieldset>\r\n\t\t\t\t<legend>Tiket Pesawat</legend>\r\n\t\t\t\t\r\n\t\t\t\t<!-- item -->\r\n\t\t\t\t\n<div class=\"control-group \">\n\t<label class=\"control-label\" for=\"item\">Item</label>\n\t<div class=\"controls\">\n\t\t <select name=\"item\" class=\"span9\">\n\t\t\t<option value=\"\" selected=\"selected\">--pilih--</option>\n<option value=\"1\">AA - American Airline</option>\n<option value=\"2\">AG - Provincial Airline</option>\n\n\t\t</select>\n\t\t\n\t</div>\n</div>\n\t\t\t\t\r\n\t\t\t\t<!-- airline -->\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"airline\" class=\"control-label\">Airline</label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"airline\" type=\"text\" name=\"airline\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<!-- unit -->\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"unit\" class=\"control-label\">Unit</label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"unit\" type=\"text\" name=\"unit\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t</fieldset>\r\n\t\t\t\r\n\t\t\t<fieldset>\r\n\t\t\t\t<legend>Rute</legend>\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"no_flight\" class=\"control-label\">Flight No.<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"no_flight\" type=\"text\" name=\"no_flight\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"no_tiket\" class=\"control-label\">Tiket No.<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"no_tiket\" type=\"text\" name=\"no_tiket\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"from\" class=\"control-label\">From<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"from\" type=\"text\" name=\"from\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">To<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"to\" type=\"text\" name=\"to\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Class<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"class\" type=\"text\" name=\"class\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Depature Date<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"depature\" type=\"text\" name=\"depature\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">ETD<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"etd\" type=\"text\" name=\"etd\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Arrival Date<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"arrival\" type=\"text\" name=\"arrival\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">ETA<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"eta\" type=\"text\" name=\"eta\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Status<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"status\" type=\"text\" name=\"status\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Booking No.<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"no_booking\" type=\"text\" name=\"no_booking\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t</fieldset>\r\n\t\t\t\r\n\t\t\t<fieldset>\r\n\t\t\t\t<legend>Selling</legend>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Basic Fare<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"basic_fare\" type=\"text\" name=\"basic_fare\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Ppn<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"ppn\" type=\"text\" name=\"ppn\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">IWJR<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"iwjr\" type=\"text\" name=\"iwjr\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">surcharge<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"surcharge\" type=\"text\" name=\"surcharge\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Surevice Fee<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"service_fee\" type=\"text\" name=\"service_fee\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Potongan Tunai<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"potongan_tunai\" type=\"text\" name=\"potongan_tunai\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Total Pax Paid<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"total_pax_paid\" type=\"text\" name=\"total_pax_paid\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t</fieldset>\r\n\t\t\t\r\n\t\t\t<fieldset>\r\n\t\t\t\t<legend></legend>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Gross Profit<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"gross_profit\" type=\"text\" name=\"gross_profit\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t\t<label for=\"to\" class=\"control-label\">Supplier<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<div style=\"margin-bottom:10px;\">\r\n\t\t\t\t\t\t\t<input type=\"radio\" name=\"supplier\" />Deposit\r\n\t\t\t\t\t\t\t \r\n\t\t\t\t\t\t\t<input type=\"radio\" name=\"supplier\" />Supplier\r\n\t\t\t\t\t\t</div>\r\n\t\t\t\t\t\t<input id=\"supplier\" type=\"text\" name=\"supplier\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Nama Penumpang<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"nama_penumpang\" type=\"text\" name=\"nama_penumpang\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">No. Telepon<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"no_telepon\" type=\"text\" name=\"no_telepon\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Email<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<input id=\"email\" type=\"text\" name=\"email\" class=\"span9\" maxlength=\"30\" />\r\n\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t\t\r\n\t\t\t\t<div class=\"control-group \">\r\n\t\t\t\t<label for=\"to\" class=\"control-label\">Remark<span class=\"required\">*</span></label>\t\t\t\t\t<div class='controls'>\r\n\t\t\t\t\t\t<textarea name=\"remark\" cols=\"40\" rows=\"5\" id=\"remark\" class=\"span9\" ></textarea>\t\t\t\t\t\t<span class=\"help-inline\"></span>\r\n\t\t\t\t\t</div>\r\n\t\t\t\t</div>\r\n\t\t\t</fieldset>\r\n\t\r\n\t\t</div>\r\n\t</div>\r\n\t\r\n\t<div class=\"modal-footer\">\r\n\t\t<button class=\"btn\" data-dismiss=\"modal\" aria-hidden=\"true\">Close</button>\r\n\t\t<input type=\"submit\" name=\"submit\" class=\"btn btn-primary\" value=\"Save Tiket\" />\r\n\t</div>\r\n\t\r\n\t</form></div>\r\n\r\n</div>\r\n","status":200,"statusText":"OK"}
这是我的网页代码:
<div class="row-fluid">
<ul class="nav nav-tabs">
<li>
<a href="<?php echo site_url() . 'admin/invoicing/reg_inv_penjualan/add_item/tiket/' . $id ?>">Tiket</a>
</li>
<li>
<a href="<?php echo site_url() . 'admin/invoicing/reg_inv_penjualan/add_item/hotel/' . $id ?>">Hotel</a>
</li>
<li>
<a href="<?php echo site_url() . 'admin/invoicing/reg_inv_penjualan/add_item/tour/' . $id ?>">Tour</a>
</li>
<li>
<a href="<?php echo site_url() . 'admin/invoicing/reg_inv_penjualan/add_item/dokumen/' . $id ?>">Dokumen</a>
</li>
<li>
<a href="<?php echo site_url() . 'admin/invoicing/reg_inv_penjualan/add_item/trans/' . $id ?>">Transportasi</a>
</li>
<li>
<a href="<?php echo site_url() . 'admin/invoicing/reg_inv_penjualan/add_item/haji/' . $id ?>">Haji</a>
</li>
<li>
<a href="<?php echo site_url() . 'admin/invoicing/reg_inv_penjualan/add_item/umroh/' . $id ?>">Umroh</a>
</li>
<li>
<a href="<?php echo site_url() . 'admin/invoicing/reg_inv_penjualan/add_item/other/' . $id ?>">Other</a>
</li>
</ul>
<?php if (isset($item)) :?>
<?php
switch ($item) {
case 'tiket':
$this->load->view('invoicing/tiket', $dataItem);
break;
case 'hotel':
$this->load->view('invoicing/hotel');
break;
case 'tour':
$this->load->view();
break;
case 'dokumen':
$this->load->view();
break;
case 'trans':
$this->load->view();
break;
case 'other':
$this->load->view();
break;
case 'haji':
$this->load->view();
break;
case 'umroh':
$this->load->view();
break;
}
?>
<?php endif;?>
</div>
开关位置是tiket。
这是我的型号代码:
/**
* method: populate Airline and Unit
*
*/
function getAirlineAndUnit($id) {
$data = array();
$this->db->select('data_airline.nama, data_item.unit');
$this->db->from('data_item');
$this->db->join('data_airline', 'data_airline.id = data_item.id');
$this->db->where('data_item.id', $id);
$q = $this->db->get();
if ($q->num_rows() > 0) {
$row = $q->row_array();
$data[] = array('nama_airline'=>$row['nama'], 'unit'=>$row['unit']);
}
return $data;
}
答案 0 :(得分:0)
最后我找到了解决这个问题的方法,问题是ajax URL不正确,因为我使用Assets :: add_js($ inline,'inline');在tiket页面上。所以URL总是返回错误。 我移动代码来查看文件夹使用名称js.php并加载到控制器上查看。这个代码:
/* get airline and unit */
$('select[name="item"]').change(function() {
$.ajax({
url: '<?php echo base_url(). 'admin/invoicing/reg_inv_penjualan/getAirlineAndUnit' ?>',
type:'POST',
data: ({
ci_csrf_token: $("input[name=ci_csrf_token]").val(),
id: $(this).val()
}),
dataType:'json',
success: function(data) {
aData = eval(data);
},
error: function(error) {
console.log( JSON.stringify(error) );
}
});
});
如果你想在ajax上加载base_url,请在第一个URL中使用'/'。
感谢。