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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:25:12+00:00 2026-05-23T04:25:12+00:00

I am using a PHP script to create JSON data. It looks like this:

  • 0

I am using a PHP script to create JSON data. It looks like this:

{"Id":0}

Now if I put that into a file and then load it using ajax it’s fine. But if I request this from the PHP script I get

parsererror | SyntaxError: Unexpected token ILLEGAL

Here is the code that I am using to load the JSON from the PHP:

$.ajax({
                    url: 'check.php',
                    data: {
                        username: 'LOL',
                        password: '1234'
                    },
                    dataType: 'json',
                    type: 'POST',
                    success: function(data) {
                        $('#result').html('#Id=' + data.Id);
                    },
                    error: function(jqXHR, textStatus, errorThrown) {
                        $('#result').html(textStatus + ' | ' + errorThrown);
                    }
                });

Here is the PHP code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<?php

    echo '{"Id":0}';

?>

Any ideas?

  • 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-23T04:25:12+00:00Added an answer on May 23, 2026 at 4:25 am

    Doctypes belong on HTML documents, not JSON.

    Try something like this in your PHP file (and only this)

    <?php
    header('Content-Type: application/json');
    ?>
    {"Id":0}
    

    Given what you have posted, I can’t see any reason to even involve PHP. I’m guessing you’ve only posted a very simple example. Should it become more complex, involving server-side processing, data retrieval, etc, use PHP’s json_encode(), for example

    <?php
    header('Content-Type: application/json');
    $data = array(
        'Id'  => 0,
        'foo' => $someOtherComplexVariable
    );
    echo json_encode($data);
    exit;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP script that executes a .bat file using system(cmd /c C:\dir\file.bat);
i have a script that calls a php file and gets an JSON object
I am using Ext.data.Store to call a PHP script which returns a JSON response
I have a PHP script where I create a new process using proc_open().It executes
I have created a dynamic list picker script using Jquery 1.3 and PHP that
Is it possible to make changes in mysql's my.ini file using PHP script?
I have a simple php script on a server that's using fsockopen to connect
I have a script that generates images from text using PHP. It's working fine
we are building a PHP script that we need at work to create reports
Using php, I'm trying to create a script which will search within a text

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.