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 7398497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T03:52:37+00:00 2026-05-29T03:52:37+00:00

I parse JSON with eval() function ` and I have an error Uncaught SyntaxError:

  • 0

I parse JSON with

eval() function
`

and I have an error

Uncaught SyntaxError: Unexpected token ILLEGAL

this is my javascript code :

var commentPerpost = document.getElementById('commentPerpost');
        var response = eval('('+receiveReq.responseText+')');
        for(var i=0;i < response.Comment.comment.length; i++) {
            commentPerpost.innerHTML += '<li><div id="Cclose" align="right">' + 
            '<input id="Userid" type="hidden" name="Userid" value="' + response.Comment.comment[i].iduser + '" /></div>' +
            '<div id="Cprofil"><img src="../91mbr27pg09/foto_profil/' + response.Comment.comment[i].ava + 
            '" style="width: 40px; height: 40px;" alt="" />' +
            '<h4 style="margin: 0; padding-top: 5px;">' +  response.Comment.comment[i].username + '</h4></div>' +
            '<div id="Cpost"><div style="max-width: 330px;">' + response.Comment.comment[i].comment +
            '</div><div class="Cdatetime">' + response.Comment.comment[i].tgl + '&nbsp' + response.Comment.comment[i].time + 
            '</div></div><div class="clearBoth BdrBottomN"></div></li>';
        }

and my php code is :

<?php

    $json = '{"Comment": {';
    if(!isset($_GET['idnews'])) {
    } else {    
    $idnews = db_input($_GET['idnews']);
    $last = (isset($_GET['last']) && $_GET['last'] != '') ? $_GET['last'] : 0;
    $sql_comment = "SELECT c.id_user, c.id_comment,c.id_judul,c.email,c.tanggal,c.id_member,c.comment,m.id,m.username,m.foto_profil,k.id,k.judul FROM comment c, member m, k_news k WHERE c.id_user = m.id AND c.id_judul = k.id AND k.id = '$idnews' AND c.id_comment > '$last'  ORDER BY c.tanggal ASC";
          $qry_comment = db_query($sql_comment);
    if(db_num_rows($qry_comment) > 0) {
          $json .= '"comment":[ ';
          while($data_comment=mysql_fetch_array($qry_comment)){
          $json .= '{';   
          $json .= '"idcomment":  "' . htmlspecialchars($data_comment['id_comment']) . '",
                      "iduser":  "' . $data_comment['id_user'] . '",
                      "username": "' . $data_comment['username'] . '",
                      "comment": "' . htmlspecialchars($data_comment['comment']) . '",
                      "ava": "' . htmlspecialchars($data_comment['foto_profil']) . '",
                      "tgl": "' . tgl_indo($data_comment['tanggal']) . '",
                      "time": "' . time_indo($data_comment['tanggal']) . '"
                         },';
            }
            $json .= ']';

    }
    else {
        $json .= '"comment":[]';
    }

    }
            $json .= '}}';
    echo $json;
?>

plesee help me how I fix the error ??

  • 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-05-29T03:52:38+00:00Added an answer on May 29, 2026 at 3:52 am

    Don’t manually cobble together JSON! You’re making some mistake somewhere and are producing invalid JSON. Let PHP take care of the details using json_encode:

    $data = array('Comment' => array());
    while (...) {
        $data['Comment'][] = array(...);
    }
    
    echo json_encode($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

See this code: var jsonString = '{id:714341252076979033,type:FUZZY}'; var jsonParsed = JSON.parse(jsonString); console.log(jsonString, jsonParsed); When
I need to parse json object for this url I have used following code
I parse data using JSON in javascript, I find this is very convenient. But
I have a javascript function that has been driving me nuts. This is the
var AppPatientsList = JSON.parse(JSON RESPONSE); var AppPatientsListSort = AppPatientsList.sort(function(a,b){ return a.firstName.toLowerCase() <b.firstName.toLowerCase() ? -1
Question: I'm using eval to parse a JSON return value from one of my
im getting response in json, but this wont parse the json response. what m
I have no problems getting the Json to work and parse the json return.
What's the foreach equivalent in jQuery (JavaScript) to parse through a JSON object and
HI, I am using the following code request.js var request; function runAjax(JSONstring) { //

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.