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

The Archive Base Latest Questions

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

I built an Ajax request with jQuery where – at the end of the

  • 0

I built an Ajax request with jQuery where – at the end of the PHP file, which is called – an array is the result:

echo json_encode(array('status' => 'true'));

Within my jQuery in the calling file, I would like to read if the status is true and I tried it with this:

    $.ajax({
        type: "GET",
        url: "logic.php",
        data: "receiver=" + receiverIds + "&subject=" + subject + "&msg=" + msg,

        success: function(data){                        
            $.each(data, function (i, elem) {
                alert(elem.status);
            });
        }
});

but the alert is always undefined. When I insert this line before the $.each:

$("#additionalTextDiv").html(data);

I get the following result: {"status":"true"}

But why is the each function not working properly?

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-27T20:13:51+00:00Added an answer on May 27, 2026 at 8:13 pm

    Change the dataType property of the options object you are setting in your AJAX call to json so the JSON string gets parsed into a JavaScript object:

    $.ajax({
            type: "GET",
            url: "logic.php",
            dataType: 'json',
            ...
    

    .ajax(): http://api.jquery.com/jquery.ajax

    Your $.each() loop works just fine, here is a demo: http://jsfiddle.net/54pB9/

    However if you are going to loop through a lot of records a for loop will perform faster:

    for (var i = 0, len = data.length; i < len; i++) {
        alert(data[i].status);
    }
    

    Here is a demo: http://jsfiddle.net/54pB9/1/

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

Sidebar

Related Questions

I have an ajax heavy web-application built using PHP, jQuery. I am looking for
  I am developing a project which is built in CakePHP and using jQuery in
I'm passing a client-side JS array to server-side VB.NET code using a jQuery AJAX
I am trying to send a from's content over AJAX POST request, using jquery.
I've built a simple sign in POST form that gets submitted via AJAX (default
I'm going to build an app which is using AJAX to load resources as
Ive built a little jquery sliding div on my website that when you hover
I am using jQuery to consume a web service I built, the input is
I'm putting together a JSON API which may or may not be built with
I came across an odd occurrence today while troubleshooting a rogue AJAX request in

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.