Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
Can't send large json for AJAX responce from PHP

I try to get a large data from mongoDB, but it returned broken on the midle, like [item, item, ite . When i request smaller data everyfing is ok. Code in php file:


if ($location) {
  //define cursor
  $rest = $collection->find(['borough' => $location]);
  //make array of restaurants names
  foreach ($rest as $restaurant) {
    if ($restaurant['name'] != '') {
      $array[] = $restaurant['name'];
    }
  }
  //forming response
  if ($array) {
    echo json_encode(
      $array,
      JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP
    );
  }
  else {
    http_response_code(204);
  }
  exit();
}

Getting " SyntaxError: Unexpected token in JSON at position 65528 " when i parse it in JS, and allways same position no matter what is a data. This is probably php problem, because if JSON make from $array=range(1,1000000) i give a same result. Any idea?

upd: sorry, coppied wrong section of code. Edited.

over 4 years ago · Santiago Trujillo
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda