D
D
DIvan4ik2015-02-20 14:51:04
PHP
DIvan4ik, 2015-02-20 14:51:04

Why is json not coming from the server?

Good afternoon!

I'm making a web face for the database. We work locally, my computer is equidistant segmentally like others. I get data using jquery - everything is fine on my computer, but others have an error. - Error: net::ERR_INCOMPLETE_CHUNKED_ENCODING ;

There is backend.php:

///...
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') {
    if(isset($_POST['json']) && $_POST['json'] == 'users') {
      $string = json_encode(getUsers(), true);
      echo $string;
    }
    exit();
}

function getUsers(){
    global $DBH;
    $STH = $DBH->prepare('correct sql');
    $STH->execute();
    $result =$STH->fetchAll(PDO::FETCH_ASSOC);
    return $result;
}
//...


And app.js

$.ajax({
                dataType: "json",
                url: 'backend.php',
                data: {json:'users'},
                success:function(data) {
                    var html = '';
                    // формирую табличку
                    $('.workers tbody').html(html);
                }
            });


String size strlen($SQLresult) ~ 400,000;

I'm looking forward to suggestions like:
header('Content-Type: application/json');
header('Content-Length: ' . mb_strlen($string));

and the like, well, let's try together, maybe I'm writing something wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor Kalashnikov, 2015-02-20
@zo0m

I would recommend you Phalcon
A very nimble extension for PHP, written in C.
It is very powerful in itself, but there is a light version of Micro for the rest back-end:
docs.phalconphp.com/ru/latest/reference/micro.html
recently on the knee glued such a thing AngularJS + REST + Plain Phalcon, may be of interest:
https://github.com/zo0m/angularjs-phalcon-rest-ze-...
though I didn’t bring it to mind, or rather brought it already in the project, then if there is time I will finalize.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question