2016-10-04 40 views
0

这里是我的第一个观点如何在笨用ajax加载另一种观点认为

<form id="bussearch"> 
<input class="form-control" id="value1" name="start" type="text" /> 
<input class="form-control" id="value2" name="value2" type="text" /> 
<input class="form-control" id="value2" name="value3" type="text" /> 
<button class="btn" type="submit">Search for Bus</button> 
</form> 

这里是脚本

$("#bussearch").submit(function(e) { 
    $.ajax({ 
     type: "POST", 
     url: "http://siteurl/controller/test", 
     data: $("#bussearch").serialize(), 
     success: function(data) 
     { 
        $("#div_result").html(data); 
      //alert(data); 
     } 
    }); 

e.preventDefault(); // avoid to execute the actual submit of the form. 
}); 

这里是我的控制器

function test() 
{ 

     $response = $this->load->view('welcome_message',TRUE); 
    echo $response; 

    } 

这里是view welcome_message

<div id="div_result"></div> 

我需要加载AJAX sucess功能后视图,但鉴于WELCOME_MESSAGE没有加载

+0

打开开发人员控制台并检查错误 –

+0

“http:// siteurl/controller/test”更改为“http:// siteurl/controller/bus_test” –

回答

1

我做一些类似的将数据加载到模态。

在我的控制器我只是呼吁观点:

public function update_user_modal() 
{ 
    $this->load->view('modals/update_user_modal'); 
} 

阿贾克斯是这样的:

$.ajax({ 
    url: "<?php echo base_url('admin/get_user_details'); ?>", 
    type: "POST", 
    data: { id: id } 
    }).done(function(msg) { 
    console.log(msg); // this will have the content of the view 
    }.fail(function(jqXHR, textStatus) { 
    alert("Request failed: " + textStatus + " - Please try again.") 
    }) 

我相信它是在AJAX网址中有错字您提供为你调用控制器中的函数test(),但是您正在控制器中提供函数bus_test()。

希望这会有所帮助。

相关问题