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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:28:58+00:00 2026-06-11T09:28:58+00:00

Problem is I can see already the value of my json through firebug but

  • 0

Problem is I can see already the value of my json through firebug but the problem is appending it to my table I try to change my json_encode from echo json_encode(array('red'=>$red, 'blue'=>$blue)); to json_encode($blue); to see if my ajax really works then the json_encode($blue); and I change my toAppend += '<tr><td>'+data.red[i]['warrior_name']+'</td><td>Name</td><td>'+data.blue[i]['warrior_name']+'</td></tr>'; to toAppend += '<tr><td>'+data[i]['warrior_name']+'</td></tr>'; then it displays perfectly in my table, but only the blue array and I want both blue and red array. So I want to know what is wrong or I have missing something?

Here’s my PHP code:

   //get blue_team attributes
$blue = array();

$blue_result = $db->dataWarrior($battle_id,$blue_name);

foreach($blue_result as $warrior){
    $blue[] = $warrior;
}

//get red_team attributes
$red = array();

$red_result = $db->dataWarrior($battle_id,$red_name);

foreach($red_result as $warrior){
    $red[] = $warrior;
}

    echo json_encode(array('red'=>$red, 'blue'=>$blue));

Here’s my ajax code:

$.ajax({
                url: "battle_review.php",
                type: "post",
                datatype: "json",
                data: { 
                    bname: blue_name,
                    btype: blue_type,
                    rname: red_name,
                    rtype: red_type },
                success: function(data){
                    var toAppend = '';
                    if(typeof data === "object"){
                        for(var i=0;i<data.length;i++){
                            toAppend += '<tbody>';
                            toAppend += '<tr><td>'+data.red[i]['warrior_name']+'</td><td>Name</td><td>'+data.blue[i]['warrior_name']+'</td></tr>';

                            toAppend += '</tbody>';
                        }
                        $("#battledata").append(toAppend);
                    }
                }
            });
  • 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-11T09:29:00+00:00Added an answer on June 11, 2026 at 9:29 am

    The structure of your output is pretty bad for a proper iteration over it. However, assuming red and blue always have the same element count you can do thi:

    $.ajax({
        url: "battle_review.php",
        type: "POST", // uppercase
        dataType: "json", // uppercase T
        data: {
            bname: blue_name,
            btype: blue_type,
            rname: red_name,
            rtype: red_type
        },
        success: function(data) {
            var toAppend = '';
            for(var i = 0; i < data.red.length; i++) {
                toAppend += '<tbody>';
                toAppend += '<tr><td>' + data.red[i].warrior_name. + '</td><td>Name</td><td>' + data.blue[i].warrior_name + '</td></tr>';
    
                toAppend += '</tbody>';
            }
            $("#battledata").append(toAppend);
        }
    });
    

    An array like this would be cleaner:

    [{"red": ..., "blue": ...},
     {"red": ..., "blue": ...},
    ]
    

    Then you could simply iterate over it and access the red and blue properties of the elements:

    $.each(data, function(i, row) {
        // row.red
        // row.blue
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem when using paperclip. I can see the files uploaded but
I can't see where is problem, but .topbar isn't centered as it should be...
I can't see this in the docs, but I presume it's a solved problem.
My problem is certainly right on my face but I can't see it... I
I asked a similar question to this already, but I still can't see the
been working on this way too long...but can't seem to identify the problem. Already
You can see the example here: http://jsfiddle.net/8EHED/8/ This is a tricky problem because I
I have a problem with the Firefox browser. You can see it here .
I have a problem with layout. Look at the picture: as you can see
I have the following problem. I am making this website you can see 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.