Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:52:37+00:00 2026-06-09T14:52:37+00:00

$.ajax is giving me a parse error about some JSON returned by my PHP

  • 0

$.ajax is giving me a parse error about some JSON returned by my PHP script. I’m somewhat manually encoding JSON with this function extending my PDO statement, in the hopes of saving some memory for very large datasets.

Why won’t this work? If I copy/paste the response text into JSON.parse in my editor, it works fine. So it’s likely some escaping issue?

Also, if I take out the top three lines (encoding x, y, and rows) and just return it an array, it works fine. Just not as my pieced together object.

public function toJSON ($x, $y) {

  echo "{x:" . json_encode($x) . ",";
  echo "y:" . json_encode($y) . ",";
  echo "rows:[";

  $i = 0;

  while ($row = $this->fetch(PDO::FETCH_ASSOC)) {

    if ($i) echo ",";
    echo json_encode($row, JSON_NUMERIC_CHECK);

    if ($i > 0 && $i % 100 === 0) {
      ob_flush();   
      flush();
    }

    $i++;
  }
  echo "]}\n";
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:52:38+00:00Added an answer on June 9, 2026 at 2:52 pm

    Are you sure you’re putting it in the correct format?

    Your name needs to be in quotations because it’s a string. If your value is a string it also needs to be in quotations.

    ex/

    echo "{x:" . json_encode($x) . ",";

    needs to be like so:

    echo '{"x":' . json_encode($x) . ',';

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Giving the following example: var animal= null; $.post(ajax.php,{data: data}, function(output){ animal = output.animal; },json);
This JS is giving me some problems. Specifically FF3.5 is saying there is Error:
HI i have done some AJAX , PHP&MySQL Sorting and it is giving me
AJAX code: <script type=text/javascript> function doCalc(){ var roomX = $('#room_str').val(); var heightX = $('#height_str').val();
ajax tutorial on w3school at http://www.w3schools.com/ajax/ajax_database.asp In this function (function GetXmlHttpObject()), it creates a
hii i am using ajax file upload in this code <script type=text/javascript src=fileuploader.js></script> <script
I have a HtmlEditor(ajax control) in which i am giving some contents to be
I have been using this PHP script for a long time and this is
This is giving me headaches, AGAIN. I either don't understand this ajax response stuff
I am using jquery with ajax. Sometimes, It is giving error $ is not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.