T
T
Thekorolev2016-02-19 01:03:17
PHP
Thekorolev, 2016-02-19 01:03:17

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>

In the controller itself, inside the index() function, there is such code that for some reason does not work:
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"));
}

Those. width and height are not passed and always given Couldn't save dimension info
CMS Opencart 1.5.5.1
CHADNT?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrzej Wielski, 2016-02-19
@wielski

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']))

S
Silm, 2016-02-19
@Silm

Dump $_POST at the very top of Index(). There are no psychics here...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question