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

  • SEARCH
  • Home
  • 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 7622027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T04:20:55+00:00 2026-05-31T04:20:55+00:00

I am using a JSON string to pass a variable in JavaScript from PHP

  • 0

I am using a JSON string to pass a variable in JavaScript from PHP :

while( $row = mysql_fetch_array($result) )
        {
                $tmp = array('id'=>$row['id'], 'alert_type_id'=>$row['alert_type_id'], 'deviation'=>$row['deviation'], 'threshold_low'=>$row['threshold_low'], 'threshold_high'=>$row['threshold_high']) ;
                $settings[] = $tmp ;
        }

        echo '{"data":'.json_encode($settings).'}' ;

in Javascript, i am using the following snippet :

console.log( result ) ;                
var json = eval('('+ result +')') ;

and what appears in the Console is the following error :

1{"data":[{"id":"1","alert_type_id":"1","deviation":null,"threshold_low":"20","threshold_high":"80"}]}

SyntaxError: Expected token ')'

Could you please help me overcome this issue please ?
Many Thanks.

  • 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-31T04:20:56+00:00Added an answer on May 31, 2026 at 4:20 am

    Well that line of code isn’t valid.

    Write in the console:

    '(1{"data":[{"id":"1","alert_type_id":"1","deviation":null,"threshold_low":"20","threshold_high":"80"}]})'
    

    As this is what you’re passing to the eval function. I should give you the same error.

    If you want to save that string in a variable you need to adjust it a bit:

    eval('var x =' + result);
    

    Anyway It looks like you’re doing something wrong, check again why do you need ti use the “evil” eval.

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

Sidebar

Related Questions

I am returning a JSON string from PHP: <?php $results = array( result =>
i pass Json String from my WebService to My code Using NSDictionary -(void)getData :(NSData*)respo{
I am using an XMLHttpRequest to POST a JSON string to PHP. The JSON
I have a problem using JSON and arrays. Here is my code: while($row =
I am using GSON to parse a Java bean and pass the JSON string
Using JSON.Net, of the following 5 tests, the first and last pass while the
I'm trying to pass a JavaScript variable to the server-side using jquery.ajax method. I'm
Using PHP 5.3 if I send a JSON encoded string as an arugment via
I'm currently trying to pass Silverlight a string value from the parent JavaScript. The
I need to pass a JavaScript Array variable to a code-behind file and access

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.