Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!