一个Ajax调用后加载视图,codeIgniter [英] loading a view after an ajax call, CodeIgniter

查看:301
本文介绍了一个Ajax调用后加载视图,codeIgniter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Ajax调用从JavaScript到控制器的方法,在控制器的方法应该是加载视图(如,在屏幕上显示一个新的页面),虽然一切似乎确定,新的视图不似乎加载在屏幕上。我不能使用页眉或windows.location因为,我传递一个数组变量,包含在视图中使用的数据。

I have an ajax call from javascript to a method in a controller, the method in the controller should be loading a view(like, show a new page on the screen), Although everything seems ok, the new view doesn't seem to load on the screen. I cannot use header or windows.location because, i am passing an array variable, containing data to be used in the view.

该网页是网络选项卡下可见(preVIEW子选项卡中,同时选择AJAX)的Chrome浏览器的调试控制台。但在主屏幕保持原样。

The page is visible under the Network tab (preview sub tab, while selecting the ajax) of the Chrome debugging console. But the main screen stays as it is.

如果有人面临着类似的问题,或有一个解决方案,请帮助我。

If somebody has faced a similar issue, or has a solution, please help me.

谢谢!

推荐答案

确定这里是你做错了什么

Ok here is what you are doing wrong.

当你使用Ajax请求的页面不返回你的页面。

when you request the page using ajax it does not return you that page.

当你使用$ this->负载>视图(页面名称',$ datapassed);它加载的观点而这就是为什么你看到什么。

when you use $this->load->view('pagename',$datapassed); it loads the view and thats why you see nothing.

什么,你所要做的就是使用

What you have to do is use

$data=$this->load->view('pagename',$datapassed, TRUE);

它会做的是它会返回一个页面,并将其保存在$数据 后,您可以使用打印

what it will do is it will return that page and save it in $data after that you can print it using

$this->set_output($data); 

和接受这一点ajax的结果,并加载它在一个div。

and receive this in ajax result and load it in a div.

如果你想刷新整个页面,您可以使用

and if you want to refresh the whole page you can use

$(body).html(result);

您要明白,你需要通过加载视图中提供了第三个参数发送的HTML页面。

You have to understand that you need to send the html page by supplying that third parameter in load view.

这篇关于一个Ajax调用后加载视图,codeIgniter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆