0

enter image description here

I have the following jquery code:

                    $.ajax({
                        type: "POST",
                        url: "Ajax/getTableRecord",
                        data:{ i : id, t: 'mylist'},                        
                        dataType: 'json',
                        success: function(data){
                            alert(data);
                        }

When I activate this, the php function getTableRecord, queries a db and ends with:

echo json_encode($array);

I can see the correct returned data in my console. However the alert function just shows the contents of the screenshot. How do I display the returned key value pairs in the alert box instead?

4
  • why don't you use console.log and view in the console ? Commented Jun 3, 2015 at 22:55
  • use console.log to print your data into the developer tools console Commented Jun 3, 2015 at 22:56
  • dataType: text , or JSON.stringify(data) Commented Jun 3, 2015 at 22:57
  • alert(data.array_key) Commented Jun 3, 2015 at 22:58

2 Answers 2

3

You can do

console.log(data);

or JSON.stringify() like this

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

Comments

2

Use the console

console.log(data); 

instead of

alert(data);

you can check how to open the console on each browser here https://webmasters.stackexchange.com/questions/8525/how-to-open-the-javascript-console-in-different-browsers

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.