在 ajax 调用后加载视图,CodeIgniter [英] loading a view after an ajax call, CodeIgniter

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

问题描述

我有一个从 javascript 到控制器中的方法的 ajax 调用,控制器中的方法应该加载一个视图(比如,在屏幕上显示一个新页面),虽然一切看起来都很好,但新视图没有似乎加载在屏幕上.我不能使用 header 或 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.

该页面在 Chrome 调试控制台的网络选项卡(预览子选项卡,同时选择 ajax)下可见.但主屏幕保持原样.

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->load->view('pagename',$datapassed);它加载了视图,这就是为什么你什么也看不到的原因.

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

你要做的就是使用

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

它会做的是,它会返回那个页面并将其保存在 $data 中之后,您可以使用

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天全站免登陆