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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:50:49+00:00 2026-05-17T18:50:49+00:00

I need (recently) to get an array from the server after an ajax call

  • 0

I need (recently) to get an array from the server after an ajax call created by jquery. I know that i can do it using JSON. But i don’t know how to implement it with JQuery (im new with JSON). I try to search in internet some example, but i didnt find it.

This is the code :

// js-jquery function
function changeSponsor() {
    $.ajax({
        type: 'POST',
        cache: false,
        url: './auth/ajax.php',
        data: 'id=changespon',
        success: function(msg) {
            // here i need to manage the JSON object i think
        }
    });
    return false;
}

// php-server function
if((isset($_POST['id'])) && ($_POST['id']=="changespon")) {
    $linkspon[0]="my ";
    $linkspon[1]="name ";
    $linkspon[2]="is ";
    $linkspon[3]="marco!";

    echo $linkspon;
}

in fact, i need to get the array $linkspon after the ajax call and manage it. How can do it? I hope this question is clear. Thanks

EDIT

ok. this is now my jquery function. I add the $.getJSON function, but i think in a wrong place 🙂

function changeSponsor() {
    $.ajax({
        type: 'POST',
        cache: false,
        url: './auth/ajax.php',
        data: 'id=changespon',
        dataType: 'json',
        success: function(data) {
            $.getJSON(url, function(data) { alert(data[0]) } ); 
        }       
    });

    return false;
}
  • 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-17T18:50:49+00:00Added an answer on May 17, 2026 at 6:50 pm

    Two things you need to do.

    1. You need to convert your array to JSON before outputting it in PHP. This can easily be done using json_encode, assuming you have a recent version of PHP (5.2+). It also is best practice for JSON to use named key/value pairs, rather than a numeric index.
    2. In your jQuery .ajax call, set dataType to ‘json’ so it know what type of data to expect.

      // JS/jQuery
      function changeSponsor() {
          $.ajax({
              type: 'POST',
              cache: false,
              url: './auth/ajax.php',
              data: 'id=changespon',
              dataType: 'json',
              success: function(data) {
                  console.log(data.key); // Outputs "value"
                  console.log(data.key2); // Outputs "value2"
              }
          });
          return false;
      }
      
      
      // PHP
      if((isset($_POST['id'])) && ($_POST['id']=="changespon")) {
          $linkspon["key"]= "value";
          $linkspon["key2"]= "value2";
          echo json_encode($linkspon);
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a query such that I need to get A specific dog All
I recently had a need to interpret a DEC 32-bit floating point representation. It
I've recently had a need to do a bit of lisp editing and I
Recently I've been doing lots of weekend coding, and have began to really need
I need more than the default diff! I have recently purchased Beyond Compare and
Need a function that takes a character as a parameter and returns true if
Need to an expression that returns only things with an I followed by either
Need a function like: function isGoogleURL(url) { ... } that returns true iff URL
Scenario: I am parsing values from an XML file using C# and have the
I was working on some code recently and came across a method that had

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.