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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:47:18+00:00 2026-06-18T17:47:18+00:00

This is all in the same script. I know the difference between ajax and

  • 0

This is all in the same script. I know the difference between ajax and serverside code. I have php interwoven in this javascript script as follows:

<script>
    <?php
        $json_string = json_encode(array("agent_table" => "<span style='float: left;'></span>"));
    ?>

    var response = $.parseJSON('<?php echo $json_string; ?>');
</script>

But parseJson is complaining of an error. The error disappears when I remove the styling from the span.

The error is ‘Unexpected identifier’. This is in Chrome.

  • 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-18T17:47:19+00:00Added an answer on June 18, 2026 at 5:47 pm

    You have ' characters in your data. These will continue to be represented as literal ' characters in the JSON.

    You are embedding your JSON directly into a JavaScript string, and that string is delimited by ' characters. The first ' that appears as data in the JSON will terminate the JS string.

    This is a general problem when embedding on data format in another. You are embedding JSON in JavaScript in HTML.

    Your options:

    • Replace every instance of ' in the JSON with \' (so they mean “Apostrophe” instead of “End of JS string”)
    • Treat the JSON as a JavaScript object literal instead of trying to munge it into a string which you run it through a JSON parser.

    The latter option is the sane one (so long as your goal doesn’t involve proving that PHP can generate valid JSON).

    var response = <?php echo $json_string; ?>;
    

    You don’t need to worry about further escaping for inserting into the HTML because the only sequence you need to worry about (inside a script element) is </script> and PHP’s json_encode will output <\/script> for that anyway.

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

Sidebar

Related Questions

I have an ObjectDataSource (but perhaps this question is the same for all kinds
I have a PHP script which calls exec() . I've been having trouble all
I know this is bad practice. Don't write code like this if at all
first of all: this is not the same as this . The ModelBackend has
I've registered 3 domains, all for the same site. I've done this to catch
I have a php script that queries a database for images, and then outputs
This (or some variation of it) is output by my PHP script Notice that
I am building an online article website. I have a php script called view_article.php
I am playing a little with some non-blocking JavaScript loading. This means I have
I'm trying to create a mosaic type script in Javascript and PHP, which makes

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.