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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:27:13+00:00 2026-05-26T15:27:13+00:00

I am trying to use a jquery getJSON get information for my table from

  • 0

I am trying to use a jquery getJSON get information for my table from a php file, and its not working. Can someone give me a few pointers as to where I am going wrong:

Javascript:

$(document).ready(function(){   
$("input#autofill").click(function()
{
$.get("last_year_ISBN.php",
    function(data){
    var isbns = $.parseJSON(data);  //creates a javascript object.
                  $.each(isbns, function(){
                    var elements = document.getElementById("booklist").getElementsByTagName("input");
                    for (var i=0, i<elements.length; i++)
                    {
                        elements[i] = this;
                    }
                    });
                  },
                  "json");

    });
});

HTML/php

<?php
            $file = fopen("SGS_Fall_Booklist.csv", "r");
            $entry= fgetcsv($file);
            echo $entry[0] . $_GET["program"] . $entry[1] . $GET["school"] . $entry[2] . $GET["term"] . "<br>";
            //COMMENTED OUT FOR TESTINGecho "<input type='submit' name='checkall' value='AutoFill (last years ISBN's)'></input><br>";
            //if ($entry[0] == $_GET["program"] && $entry[1] ==$GET["school"] && $entry[2] == $GET["term"])
            //{                                 
            echo "<table id='booklist'><tr>
                             <th>Edit</th>
                             <th class='coursename'>" . $entry[6] . "</th>
                             <th class='startdate'>" . $entry[7] . "</th>
                             <th class='booktitle'>" . $entry[17]. "</th>
                             <th class='author'>" . $entry[18]. "</th>
                             <th class='isbn'>" . $entry[16]. "</th>
                         </tr>";
            while(! feof($file))
            {
                $entry = fgetcsv($file); 

                echo    "<tr>
                            <td><input type='checkbox'></input></td>
                            <td class='coursename'>" . $entry[6] . "</td>
                            <td class='startdate'>" . $entry[7] . "</td>
                            <td class='booktitle'>" . $entry[17]. "</td>
                            <td class='author'>" . $entry[18]. "</td>
                            <td class='isbn'><input class='ISBN_number' type='text' value='";               

                if(isset($_GET["checkall"]))
                {
                    echo $entry[16];
                }
                echo        "'size='13' maxlength='13'></input></td>    
                      </tr>";                   
            }

            //}
            echo "</table>";
            fclose($file);

?>

external php file

<?php
$file = fopen("SGS_Fall_Booklist.csv", "r");
$entry = fgetcsv($file);    //discard the first title line
$i=0;
while(! feof($file))
{
    $entry = fgetcsv($file); 

    $isbns=[$i] = $entry;
    $i++;
}
fclose($file);
echo json_encode($isbns);
?>

I have changed my code as hyperslug suggested and it still doesn’t work. The alert(data) does return the whole json statement. What am I missing?

$(document).ready(function(){   
    $("input#autofill").click(function()
    {
        $.get("last_year_ISBN.php",
                  function(data){
                  alert(data);
                  var isbns = $.parseJSON(data);    //creates a javascript object.
                  var elements = $('#booklist .ISBN_number');
                  $.each(isbns, function(index, obj){
                    //var elements = document.getElementById("booklist").getElementsByTagName("input");
                    //for (var i=0, i<elements.length; i++)
                    //{
                        //elements[i].value = this;
                    //}
                    $(elements[index]).val(obj);
                    });
                  },
                  "json");



    });
});

I finally figured out my problem! I was using json_encode on the php side which sends the request back as json. The .get call was reading it in AS JSON (note the last parameter) and automatically turning it into a javascript object. Therefore, of course my parseJSON line wouldn’t work, I was parsing a javascript object, not json text!!

  • 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-26T15:27:13+00:00Added an answer on May 26, 2026 at 3:27 pm

    Your jQuery .each loop gives you an index and a reference to each object in isbns. If isbns is a simple array and has exactly the same number of elements as your booklist has rows,

    var elements = $('#booklist .ISBN_number');
    $.each(isbns, function(index, obj){
        $(elements[index]).val(obj);
    });
    

    should fill your ISBN <input> fields.

    If isbns is actually an array of objects, you’ll have to reference that value by name:

        $(elements[index]).val(obj.ISBN);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use jQuery.getJSON to get data from a domain I don't own
I'm trying to use jQuery to get data from an ASP.NET web service (SharePoint
I aam trying to GET an array from a JSON file using JQuery's ajax
I'm trying to use JQuery's $.getJSON to access Model data from the Controller, and
I am trying to use jQuery's ajax functionality to update data from a web
I am trying to make a get http request using jquery getJSON function. I
I've managed to get a JSON output from my database for use with jQuery
i'm trying for days to get this working.. but i still fail. <?php $province
I was trying to use $.getJSON to go through the json arrays from the
According to my previous post I am trying to get back some information from

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.