开发者

codeigniter, set_flashdata('abc', 'hi);

开发者 https://www.devze.com 2023-01-30 17:40 出处:网络
I am using codeigniter on my project. when page refresh, in controller page, $this->session->set_flashdata(\'abc\', \'hi);

I am using codeigniter on my project.

when page refresh,

in controller page,

$this->session->set_flashdata('abc', 'hi);

in view page, echo

$this->sessio开发者_C百科n->flashdata('abc'); 

works fine.

but, when ajax call, not page refresh, controller,

 $this->session->set_flashdata('abc', 'hi);

view,

echo $this->session->flashdata('abc'); 

doesn't work.....

echoing nothing~ -_-; ajax doesn't have mechanism to catch session flash data?

any idea?


flash data is store up to the next http request.

if you need it longer use:

$this->session->keep_flashdata('item');


You probably should not use flashdata

You just need to echo. The echo should come from your controller method. and your javascript accepting the response should insert it into an element in your page.


Your Ajax call will only ouput whatever the Controller/Method prints to the output buffer. So if you add

echo $this->session->flashdata('abc'); 

to your controller that gets called by the Ajax method, it will return the echo to the Ajax method which u can then display on the page. The echo statement in the view will only get executed when your page is refreshed, since PHP has to compile that echo statement on the server at run time and then return the result to your browser.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号