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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:47:13+00:00 2026-06-04T14:47:13+00:00

I have an ajax question for you all. I want to return an array

  • 0

I have an ajax question for you all.
I want to return an array from an ajax call in php and then get the values from that array that I return for use with a jquery ajax call, but I don’t know how to do this. Can anyone point me in the right direction for a tutorial?

I know there’s a bunch of different encoding types for ajax responses (json and xml come to mind) but I don’t know really what there use is. Right now all I do is echo what I have as a response to get some things displayed on my page, but I want to change my current implementation to use an array as the response rather than just simple text. Though I don’t know where to start in looking at tutorials on how to do this.

Also, what is the point of using the encoding types if I can just echo my text out and get what I want? I guess I really don’t see the point of the json type or xml if I can just echo for 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-06-04T14:47:14+00:00Added an answer on June 4, 2026 at 2:47 pm

    If you’re returning arrays, I think JSON is the best way to go.

    Its actually really easy to do.

    PHP:

    $array=array();//this is my array
    
    $array=json_encode($array);//encode the array to JSON format, so that jQuery can decode it.
    
    echo $array;//print it on screen
    

    Now use some jQuery:

    $.getJSON('http://mysite.com/myphpscript.php', function(my_data){
    
    //now, my_data is your array..
    
    //so access it like this:
    
    alert(my_data.keyname);//"keyname" is an array key of your array
    
    });//end of ajax request
    

    The point of encoding your array is so that jQuery can pick it up as an array (with the help of JSON), and not just standard text.

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

Sidebar

Related Questions

I have ajax code for asp.net (non-mvc) to call to a webMethod to get
I have a AJAX post method that gets xml data from server. But when
silly quick question: I have my: $('#result').load('ajax/test.html'); but what if I don't want to
I have a webpage that receives AJAX data with values listing_id, lat, lng using
This is more of a general design question I guess... I have an Ajax
I have a question about how ASP.NET AJAX partial rendering actually works. Does it:
I have implement the exact same concept for my project- http://blog.perplexedlabs.com/2009/05/04/php-jquery-ajax-javascript-long-polling/ My question is,
I have ajax request that do 3 missions: Save Model (DB) Send Email Give
I have a series of dynamically generated inputs that I need to have ajax
I have an Ajax form that updates a div when submitted with a submit

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.