Javascript 如何将在新窗口中创建的新元素的数据返回到下拉列表中
我正在使用codeigniter和grocerycrud 我有一个视图,在这个视图中我有一些下拉列表,这些下拉列表是从控制器输入的:Javascript 如何将在新窗口中创建的新元素的数据返回到下拉列表中,javascript,php,jquery,codeigniter,grocery-crud,Javascript,Php,Jquery,Codeigniter,Grocery Crud,我正在使用codeigniter和grocerycrud 我有一个视图,在这个视图中我有一些下拉列表,这些下拉列表是从控制器输入的: public function programar_ruta() { if($this->model_privilegios->validar_usuario()==true) { $data['destinos'] = $this->model_querys_usuario->get_
public function programar_ruta()
{
if($this->model_privilegios->validar_usuario()==true)
{
$data['destinos'] = $this->model_querys_usuario->get_destinos();
$this->load->view('usuario/dynamic_form2',$data);
}
}
我的型号功能代码:
public function get_destinos ()
{
$this-> db ->select('*');
$this-> db ->from('destinos');
$this -> db -> where('empresa', $_SESSION['empresa']);
$query = $this->db->get();
return $query->result();
}
在我的表单中,我有下拉列表和一个指向控制器函数的按钮,该函数允许添加一个新的“Destino”:
我认为ajax是最好的方式,您可以尝试以下方式:
...
var addedData = $(this).closet('origen0').find('input_id').val();
$.ajax({
url: <?php echo base_url('index.php/usuario/destinos/add');?>,
type: 'POST',
data: addedDate
...
。。。
var addedata=$(this.clock('origen0').find('input_id').val();
$.ajax({
网址:,
键入:“POST”,
数据:addedate
...
是的,通过AJAX-
以下是我将带您经历的内容:
1) 。打开的窗口将显示一个窗体,该窗体将目标添加到数据库中
2) 。计时器脚本将等待窗口关闭,然后获取新的destino并将其添加到菜单中
3) 。您需要添加处理JS请求的服务器端脚本
所以-!首先,您需要去掉“onClick”,并在单独的位置处理JS-
让我们从改变开始:
因此,澄清一下,它是这样的:点击按钮,打开一个新窗口,其中包含一个表单-填写表单时,它提交创建一个新的目的地-然后窗口关闭。在现有页面上,您希望将新的目的地填充到下拉菜单中。对吗?OmgTVM我将实现它并关闭你不知道。同时,如果你能对这个答案投上一票,那就太棒了。当然,顺便说一下,在这一行中,“在;之前是一个拼写错误吗?或者应该在那里吗?”窗口。打开('/index.php/usuario/destinos/add','Nuevo Destino','width=800,height=600');
...
var addedData = $(this).closet('origen0').find('input_id').val();
$.ajax({
url: <?php echo base_url('index.php/usuario/destinos/add');?>,
type: 'POST',
data: addedDate
...
$("#newDestino").click(function(){
var desinoMas = window.open('/index.php/usuario/destinos/add','Nuevo Destino','width=800,height=600');
var windowCloseChecker = setInterval(function() {
if (win.closed) {
clearInterval(timer);
addDestino();
}
}, 1000);
});
function addDestino(){
$.ajax({
url : "index.php/usuario/destinos/updateClientMenu",
method: "POST" // this is really irrelevant,
success: function(response){
$("#origen0").html(response);
}
});
}
<?php
//[...] You'll obviously need to re-query for the destinos, here.
foreach($destinos as $row)
{ $response .= '<option value="'.$row->nombre.'">'.$row->nombre.'</option>'; }
echo $response;
?>