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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:46:07+00:00 2026-05-29T15:46:07+00:00

I am having trouble with loading JSON into an app that im creating $(#load_basic).click(function(){

  • 0

I am having trouble with loading JSON into an app that im creating

  $("#load_basic").click(function(){

  $.ajax({
    url: 'php/show.php',
    method: 'get',
    dataType: 'json',
    success: function(json) {
      $("#textarea").html(json.doc);
    }
  });
});

My JSON from show.php is as follows

{
"id": "1",
"title": "doc 1",
"doc": "Lorem Ipsum",
"lastsaved": "2012-02-12 08:33:49"
} {
"id": "3",
"title": "doc 2",
"doc": "another lorem ipsum document",
"lastsaved": "2012-02-12 08:39:31"
}

Please can anyone help. Firstly I was attempting to do it locally and I thought this might be the problem but now Ive tried it live on the server and still no joy. Any ideas?

This is the show.php source for creating the JSON file

<?php
header('Content-type: application/json');
include 'db.php';
 $query = 'SELECT * FROM docs';
 $result = mysql_query($query) or die('<p class="db_error"><b>A fatal MySQL error    occurred while trying to select <b>EVERYTHING</b> from the database.</b><br />Query: '.$query.'<br />Error: ('.mysql_errno().') '.mysql_error().'</p>');

 while ($row = mysql_fetch_assoc($result)) { 
      $arr = array('id'=>$row['id'],'title'=>$row['title'],'doc'=>$row['doc'],'lastsaved'=>$lastsaved = $row['lastsaved']);
        echo json_encode($arr);
 }//end while
?>
  • 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-29T15:46:07+00:00Added an answer on May 29, 2026 at 3:46 pm

    The JSON which you have uploaded is not valid JSON. What I think you have expected is array of JSON, looking like following.

    [{
    "id": "1",
    "title": "doc 1",
    "doc": "Lorem Ipsum",
    "lastsaved": "2012-02-12 08:33:49"
    }, {
    "id": "3",
    "title": "doc 2",
    "doc": "another lorem ipsum document",
    "lastsaved": "2012-02-12 08:39:31"
    }]
    

    Notice existence of square brackets and commas. To get output like this, use json_encode() on array of objects (or associative arrays, depending on what you’re using), instead of echoing every separately. For example instead of:

    while ($row = mysql_fetch_assoc($result)) { 
        $arr = array('id'=>$row['id'],'title'=>$row['title'],'doc'=>$row['doc'],'lastsaved'=>$lastsaved = $row['lastsaved']);
        echo json_encode($arr);
    }//end while
    

    Do:

    $arr = array();
    while ($row = mysql_fetch_assoc($result)) { 
        $arr[] = array('id'=>$row['id'],'title'=>$row['title'],'doc'=>$row['doc'],'lastsaved'=>$lastsaved = $row['lastsaved']);
    }//end while
    echo json_encode($arr);
    

    If you have a lot of data which might not fit into memory as single array, you can try:

    1. echo [ character
    2. For every object you want to parse:
      1. echo , character unless it’s first object
      2. echo JSON for your object
    3. echo ] character
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble loading JQueryUI from Google's CDN. I've got an ASP.NET application that
I'm having a bit of trouble loading pages into an already-existing colorbox. I have
I'm having trouble loading the mysql data to the option box using php. Here's
hey people im having trouble with loading my array of strings into a tableview
I'm having trouble loading custom HTML into my UIWebView without breaking its goBack method.
Morning, I'm having some trouble creating tables/loading fixtures. (symfony 1.4.6 with the bundled Doctrine
I'm having trouble efficiently loading data into a sparse matrix format in R. Here
Ok, I'm having trouble finding an answer to this that isn't just use JSON
I'm having trouble loading data from sqlite database into a detailed view. The table
I am having trouble loading .swf files to my flash app off my cloudstorage

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.