Javascript codeigniter 3上的loadData()函数
如何在CodeIgniter 3上使用JavaScript loadData函数? 我有一个交易视图,其中包含要购买的详细项目,我想使用loadData加载详细视图 这是我的文件结构:Javascript codeigniter 3上的loadData()函数,javascript,php,codeigniter,codeigniter-3,Javascript,Php,Codeigniter,Codeigniter 3,如何在CodeIgniter 3上使用JavaScript loadData函数? 我有一个交易视图,其中包含要购买的详细项目,我想使用loadData加载详细视图 这是我的文件结构: myproject: -application --controller ---admin -----dashboard.php -----transaction.php ---home.php --model ---mymodel.php
myproject:
-application
--controller
---admin
-----dashboard.php
-----transaction.php
---home.php
--model
---mymodel.php
--view
---transaction
----transaction_index.php <- the view that I want to use for calling
----transaction_detail.php <- the view that I want to call
---home.php
看起来您正试图使用jQuery和CodeIgniter在div内部加载HTML视图。我会利用jQuery提供的or,因为您已经在使用它了 javascript代码示例如下所示:
// var site_url returns your codeigniter application's URL by splitting it before index.php.
// if you're using .htaccess or mod_rewrite for pretty urls (no index.php, you may need to find another way to get the URL of your site)
var site_url = window.location.protocol + '//' + window.location.hostname + window.location.pathname.split('index.php')[0] + 'index.php';
//do a GET request for the transaction/getDetail endpoint
$.get(site_url + 'index.php/transaction/getDetail', function(html) {
//load the HTML returned by the codeigniter controller into the #t_detail element
$("#t_detail").html(html);
});
如果您认为这解决了您的问题,请将其标记为已接受的答案。仍然没有显示任何内容,我必须包括'index.php'吗?我在我的URL上不使用index.php,我使用.htaccess重写,但在此之前谢谢。如果您不使用.htaccess,您可以尝试类似于
window.location.protocol+'/'+window.location.hostname
。。。如果你的应用程序不在子目录中,这将起作用。如果它位于子目录中,您将希望以不同的方式获取您的站点URL。您说它仍然没有显示任何内容。。。您是否从PHP或Javascript(通过控制台检查)中得到任何错误?我使用上面的脚本跟踪另一个CI项目,并对其进行了处理,但对我来说不是,我仍在学习使用CI,您能给我一些使用上面的loadData(args)的方法吗?
$(document).ready(function(){
function loadData(args){
$("#t_detail").load("<?php echo base_url('admin/transaction/getDetail'); ?>");
}
loadData();
function emptying(args){
$("#id").val();
$("#name").val();
$("#category").val();
$("#price").val();
$("#total").val();
}
})
public function getDetail(){
$data['temporary'] = $this->mymodel->getAllData('temporary')->result();
$data['limit'] = $this->mymodel->countAll('temporary');
$this->load->view('transaction/transaction_detail', $data);
}
// var site_url returns your codeigniter application's URL by splitting it before index.php.
// if you're using .htaccess or mod_rewrite for pretty urls (no index.php, you may need to find another way to get the URL of your site)
var site_url = window.location.protocol + '//' + window.location.hostname + window.location.pathname.split('index.php')[0] + 'index.php';
//do a GET request for the transaction/getDetail endpoint
$.get(site_url + 'index.php/transaction/getDetail', function(html) {
//load the HTML returned by the codeigniter controller into the #t_detail element
$("#t_detail").html(html);
});