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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:41:44+00:00 2026-05-29T05:41:44+00:00

I am ‘echoing’ a json array back to ajax, but it is printing the

  • 0

I am ‘echoing’ a json array back to ajax, but it is printing the entire array to the screen. I am at my wits end! Can someone see anything wrong with the following code that would cause this?

My ajax call:

theUrl = 'myphpquerypage.php?id=somenumber'

$.getJSON(theUrl, function(data) {        
    var content = "";
    $.each(data, function(index, array) {
        content += "<div>" + array.filename + "</div>";
        $(content).appendTo('#myContentDivTag');

myphpquerypage.php:

    $pdo = new PDO($dsn, $username, $password);
    $rows = array();
if(isset($_GET['id'])) {
    $stmt = $pdo->prepare("call getimages(?)");
    $stmt->execute(array($_GET['id']));
    $rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
echo json_encode($rows);

The echo is causing this to go directly to the screen (nothing shows up in #myContentDivTag):

[{"filename":"img4dc458200caa7.jpg"},{"filename":"img41b65171bd651.jpg"},    {"filename":"img41be6c0eae1a4.jpg"},{"filename":"img41e5d5eede9da.jpg"},    {"filename":"img41e5d64383039.jpg"},{"filename":"img422fb82b3768a.jpg"},    {"filename":"img422fc528cc8d1.jpg"}]

Thanks everyone, any help would be greatly appreciated. I have spent hours trying different things. Obviously I am getting the json encoded array back, but I cannot get it to properly display.

  • 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-29T05:41:45+00:00Added an answer on May 29, 2026 at 5:41 am

    I suppose we have different ways of dealing with JSON data in ajax requests, and though yours isn’t wrong, mine seems to work 😉

    Here is an example of how I’d do it, seems to work fine:http://jsfiddle.net/5YWpr/3/
    (Note, it uses jsfiddle’s ajax tester, so it posts sample json data to be returned, why the ajax request looks weird, use the one in this thread if you just want to insert the code).

    Javascript:

    $.ajax("myphpquerypage.php",
    {
        dataType: "json",
        type: "get" /*can also be post*/,
        data: {id: "somenumber"},
        success: function(data)
        {
            var content = "";
            for (var key in data)
            {
                content += "<div>" + data[key].filename + "</div>";
            }
    
            $("#test").append(content);
        }
    });
    

    HTML:

    before div
    
    <div id="test">
    </div>
    
    after div
    

    Tell me how it goes.

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I'm creating a web service to transfer json to an iPhone app. I'm using
I need to clean up various Word 'smart' characters in user input, including but
Does anyone know how can I replace this 2 symbol below from the string
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am trying to create a RegEx expression that will successfully parse the following
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.