Why jqgrid can't get json data from joomla? - ajax

I write codes for using jqgrid(version 4.4.4) in joomla(version 2.5.9).this is my codes I found the jqgrid cann't display data from joomla json_encode.but no in joomla is OK.
if jqgrid url:testjson.php is ok.
<?php
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header("Content-Type: application/json;charset=utf-8");
header('Content-Disposition,attachment;filename=”json.json”');
$response=new stdClass();
$response->page = 1;
$response->total = 1;
$response->records = 1;
$response->rows[0]['id']='1';
$response->rows[0]['cell']=array("1","vlan");
echo json_encode($response);
?
I get json:{"page":1,"total":1,"records":1,"rows":[{"id":"1","cell":["1","vlan"]}]},and jqgrid work fine.
When jqgrid url:index.php?option=com_sysconfig&view=vlan&task=ajaxvlane.getvlanlist&format=raw
In sub-controller,in function getvlanlist,this codes is blow:
<?php
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header("Content-Type: application/json;charset=utf-8");
header('Content-Disposition,attachment;filename=”json.json”');
$response=new stdClass();
$response->page = 1;
$response->total = 1;
$response->records = 1;
$response->rows[0]['id']='1';
$response->rows[0]['cell']=array("1","vlan");
echo json_encode($response);
JFactory::getApplication()->close();
?>
Through firebug i can see the json:{"page":1,"total":1,"records":1,"rows":[{"id":"1","cell":["1","vlan"]}]} same as testjson.php result.
but jqgrid can't show any data.
What error causes a problem?thank you.
BTW,if I use joomla creating xml data ,jqgrid work fine.

I get the answer:because the code editor is UTF8 BOM charaset.If use no BOM uft-8,then it work fine.

Related

Session message repeat when click browser back

I want to show a session message after login. i do it using this
#if ($message = Session::get('success'))
<script>
toastr.success('{{ $message }}');
</script>
#endif
but when navigate another web page and click again browser back button . it shows previous session message . How can i remove session messages on browser back button.
I tried
{{ Session::forget('success') }}
it always forget session message. Even not display first time session.
Its because of cache.
you can use headers before sending response
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
There is a answer that can help you
prevent-browsers-back-button-login-after-logout-in-laravel

How to download files from db in codeigniter

I am creating a resource site for my campus where teachers upload files to folder and reference of that filed stored in db, and students can download those files using download option in student view side, and all these I have done in codeigniter using model view controller.
I need help for coding to download files. I managed to display a set of files but could not download yet, can anyone please help me with this? I'll be so thankful.
Try this
$download_file = 'C:\example.zip';//path of the file
$content_type = mime_content_type($download_file);//mime type of the file
$file_name = basename($download_file);//file name
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: ".$content_type);
header("Content-Disposition: attachment; filename=\"".$file_name."\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($download_file));
while (ob_get_level()) {
ob_end_clean();
}
readfile($download_file);

Codeigniter Flash data not getting cleared

public function student_email()
{
$opt=$this->uri->segment(3);
$class=$this->input->post('class');
$edu_level=$this->input->post('edu_level');
$data=$this->newsletter_model->get_StudentData($opt,$class,$edu_level);
$subject=$this->input->post('txtSubjectRequired');
$message=$this->input->post('txtMessageRequired');
$message=nl2br($message);
$note="student";//Variable for Identifying Students alone
//Test Email
$email=$this->input->post('txtEmail');
if(trim($email)!=''){
$note="test";
$name="User";
$data=$email;
$this->sendMail($data,$subject,$message,$note,$name);
}
else {
//$this->sendMail($data,$subject,$message,$note,$text,$name='');
}
if($this->session->userdata('mail_status')=="success"){
$this->session->set_flashdata('success', 'Mail sent Successfully.');
}
else{
$this->session->set_flashdata('success', 'OOPS.! Mail Sending failed..!.');
}
$this->session->unset_userdata('mail_status');
redirect('/newsletter/student/'.$opt , 'refresh');
/**Note:
* Filter by field of study and Last topic need to be coded..
*/
}
When click the back button, flash data not getting cleared.
is it a cache problem..? any other
any solution instead of disabling cache?
Please help me with the solution..
<?php
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
?>
I found this code
It solves the problem..

CI load view via jquery

hi guys im loading popup screen in this way
<script>
function show_popup(){
$('#popup-container').load(html);
$('.popup').fadeIn();
}
</script>
on my html
<a onlick="show_popup('popup/view-content')" href="#">
my problem is when the html was loaded the previous html loaded can be seen for awhile before the new one shows up.. how can i unload the previous html.
the view seems to cache displaying the previous html how can i erase the previous html then load the new one
To remove caching from a page you need to include this at the top of your page:-
$this->output->set_header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
$this->output->set_header("Last-Modified: " . gmdate("D, d M Y H:i(worry)") . " GMT");
$this->output->set_header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
$this->output->set_header("Cache-Control: post-check=0, pre-check=0", false);
$this->output->set_header("Pragma: no-cache");

Preventing ajax-jquery loaded external file from caching in IE

I have this jquery script to call an external file. So far so good. The script is working fine, but as always IE makes what he wants. The external file that I load with this script (weather.php) is a file with real-time weather conditions data in it. Whit this script, I can refresh the div inside which is my weather.php file. And obviously I don't want IE to cache the data in this file. I want when someone click on button "REFRESH", the included page to be reloaded with the new data in it. In IE this doesn't happens because of the cache.
How can I change this script to not cache the div's content, or how can I say to my included file (weather.php) to do not cache it self?
This is the script:
function ajax_request() {
$('#column_weather').html('<img src="../images/home/ajax-loader.gif" width="16" height="11" style="vertical-align:middle;"/><b> Loading...</b>');
$('#column_weather').load("../includes/home/weather.php");
}
`
And that's how I call the script:
Refresh`
Put a random variable on your query String
$('#column_weather').load("../includes/home/weather.php?myRand=" + guid());
I would make random var return a guid
function s4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function() guid{
return s4()+s4()+"-"+s4()+"-"+s4()+"-"+s4()+"-"+s4()+s4()+s4();
}
Can't you just have proper caching instructions inside this weather.php file (to say not to cache it)
I would attach the current date and time as a GET parameter. Internet Explorer (and other browsers) view this information as critical to loading the page, just as any function returns a different value with different parameters. The trick is that you don't have to use the parameter. :)
$('#column_weather').load("../includes/home/weather.php?t=" + date());
Adding a random parameter to the end of the query URL will help, but try adding this to the beginning of weather.php:
<?php
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', FALSE);
header('Pragma: no-cache');
?>

Resources