Answer the question
In order to leave comments, you need to log in
Why is data not being passed in json?
Hello! I pass data about the user's screen resolution to the header controller using json.
<script type="text/javascript">
$(function() {
$.post('index.php?route=common/header', { width: screen.width, height: screen.height}, function(json) {
if(json.outcome == 'success') {
alert('success!');
} else {
alert('Unable to let PHP know what the screen resolution is!');
}
},'json');
});
</script>
if(isset($this->request->post['width']) && isset($this->request->post['height'])) {
$this->session->data['screen_width'] = $this->request->post['width'];
$this->session->data['screen_height'] = $this->request->post['height'];
echo json_encode(array('outcome'=>'success'));
} else {
echo json_encode(array('outcome'=>'error','error'=>"Couldn't save dimension info"));
}
Answer the question
In order to leave comments, you need to log in
You are only passing width
And check for the presence of width and height in the request
if(isset($this->request->post['width']) && isset($this->request->post['height']))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question