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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:14:23+00:00 2026-05-18T04:14:23+00:00

I am getting ajax response in array format from php url. How to extract

  • 0

I am getting ajax response in array format from php url. How to extract array response values in jQuery?
FYI:

PHP array is:

$response = array('msg' => 'Hello', 'html' => '<b>Good bye</b>');

I am getting $response array in my ajax response. i.e.

var promo = "promo=45fdf4684sfd";
$.ajax({
    type: "POST",
    url: baseJsUrl + "/users/calc_discount",
    data: promo,
    success: function (msg) { // I am getting $response here as ajax response.
        //alert(msg);

        // Here I want to check whether response is in array format or not. if it is in array format, I want to extract msg here and want to use response array values.
    }
});

Let me know answer pls.
Thanks.

  • 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-18T04:14:23+00:00Added an answer on May 18, 2026 at 4:14 am

    You should echo that $response with json_encode().

    You should probably set dataType: 'json' too inside the object literal you send to $.ajax().

    Then you can access it natively with JavaScript using the dot operator inside your success callback…

    function(msg) {
        alert(msg.html);
    }
    

    BTW, this line…

    $response = array(['msg'] => 'Hello', 'html' => '<b>Good bye</b>');
    

    … isn’t valid PHP. Remove the brackets from the first key.

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

Sidebar

Related Questions

I'm having trouble getting a response back from a Jquery ajax call... (It's a
I am having a peculiar problem with getting an integer from an ajax response.
Getting the subdomain from a URL sounds easy at first. http://www.domain.example Scan for the
Getting started with jquery and having trouble getting hello world type example going for
i'm trying to make a test with ajax response using an external array as
Ajax response I am getting is always empty! Interestingly, if I copy paste that
With $.ajax , I'm getting a JSON response like follows: [{project:{name:P1111, description:I like chicken
I am just getting started creating an AJAX application using server side push. I
Im getting a string (simplified) from the backend that should be : { menu:
My html of form is like this <form id=form method=post action=func.php> <table> <!--- DATA

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.