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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:35:54+00:00 2026-06-10T07:35:54+00:00

I have to make a JSON ajax request and have an array in return.

  • 0

I have to make a JSON ajax request and have an array in return.

i found this code on multiple other questions (edited to my problem):

var hej[];
function ajax_search(){ 
    $.getJSON('test.php',function(response){
    var data = response.get_response;
    for (i in data){
      hej.push([i,data[i]]);
    }
alert(hej[0]);
}

In the php part, i have a database from which i need the data i have have 5 columns pr. row. I only have one row, and i need all five columns in the array.

$sql = "SELECT * FROM 'table'
   LIMIT 1 OFFSET $i"; //random offset
$result = mysql_query($sql);

$storeArray = Array();
while($row = mysql_fetch_array($result))
{
    $storeArray[0]=$row['column1'];
    $storeArray[1]=$row['column2'];
    $storeArray[2]=$row['column3'];
    $storeArray[3]=$row['column4'];
    $storeArray[4]=$row['column5'];
}
$json = json_encode($storeArray);
echo $json;

I know im doing something wrong, and i am new to programming. I need to be able to access all column values in my javascript after the call and use them in other functions, but i cant get it to return.

I would really appriciate help, with both the javascript and the php if there are errors in either.

  • 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-10T07:35:55+00:00Added an answer on June 10, 2026 at 7:35 am

    It should be:

    function ajax_search(){ 
        $.getJSON('test2.php',function(response){
            // response.column1
            // response.column2
            // response.column3
    
            // for array push:
            var hej = [];
            $.each(response, function(key, val) {
                 hej.push(val);
            });
            alert(hej[0]); // it will alert column1
        });
    
    }
    

    and MySQL:

    $sql = "SELECT `column1`, `column2`, `column3`, `column4`, `column5` FROM `table` LIMIT 1 OFFSET $i"; //random offset
    $result = mysql_query($sql);
    $row = mysql_fetch_assoc($result);
    $json = json_encode($row);
    echo $json;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code for make some request to my server: function myAjaxCheck(token) {
I have this json string: $row['medium'] = {\medium\:13|17|1|14, \medium_sub\:21}; now I want to make
I'm using jQuery (1.7.0) to make a json/ajax call to Spotify. The following code
I have the following code: $.ajax({ type: POST, url: url, data: sendable, dataType: json,
Basically, I have an AJAX request like this: $.ajax({ url: http://192.168.0.100/, success: function(x) {
Alright, so I have some jQuery code that will send an AJAX request to
I make an ajax call and return some JSON when my user submits a
Scenario: My app has to make a request (AJAX) and based on request multiple
I have the following code in my main page, trying to pull AJAX JSON.
We have a uiWebview which uses jquery to make an ajax request in order

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.