1

I know that this question is so simple to ask, but I wasn't able to find the right answer for it, by going through many questions on stack overflow or by googling. So I found noway but to place the question here.

I have a mysql table as follow:

 [0]1>>>>2>>>>>3>>>>>5>>>>>6
 [1]1>>>>2>>>>>3>>>>>5>>>>>6
 [2]1>>>>2>>>>>3>>>>>5>>>>>6
 [3]1>>>>2>>>>>3>>>>>5>>>>>6
 [4]1>>>>2>>>>>3>>>>>5>>>>>6
 [5]1>>>>2>>>>>3>>>>>5>>>>>6

I need to store it in a variable and parse it with json back to the ajax function, but the result I get is [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],

Here is the php code:

 $ent = $_POST['id'];
 $column = array();
 $gtord = mysql_query("SELECT * FROM order WHERE oId = '$ent' ");
 while($rowmnu2=mysql_fetch_assoc($gtord))           
{
   $column[]  = array($rowmnu2);
}
  echo json_encode($column);

here is the ajax function:

 $.ajax({
  type: 'POST',
  url: "profile/ajax/getorder.php",
  data: {id:gotid},
  dataType: 'json',
  cache: false,
  success: function(result) {
          alert(result);
     },
   }); 

I am sure that there is an error in my ajax code success alert, but I am not able to figure it out, how to go through the received array.

Please help me. Appreciated in advance.

4
  • Try $column[] = $rowmnu2 Commented Jan 1, 2014 at 6:38
  • @Nouphal.M, I did try that too, the php file itself will echo the whole array correctly, but the ajax still alerts object :( Commented Jan 1, 2014 at 6:42
  • If you want to go through the received array, write a for loop. alert() doesn't show the contents of objects, use console.log() to see the data. Commented Jan 1, 2014 at 6:42
  • @Barmar, ok I'll need to search about how to use console.log then :(, but is that the only way ??? Commented Jan 1, 2014 at 6:48

1 Answer 1

1

Try:

alert(JSON.stringify(result));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.