1

I am working in some code for school and has spend a couple of days looking thru post's but can't find a solution, this is actually my first post and welcome everyone who take the time to help!

I am coding a restful JSON API which I can send the data to the web service, however when I tried to read it and send the data to a textarea, I either get [object, Object] or a 0 (which I think is the index for the array generated from the json).

This is my code for the read function:

function cargarInfo(){
    $.get("http://localhost:8080/Lec09/miApi/acciones", function(data, status){
       var personas = data.personas;

       document.getElementById("info").value = personas;
    });
}

When I debug on chrome I can see the Object and the values, I think this is a realy noob question however IDK why I can't figure it out, it is suposed to show the json {nombre:xxxx apellidos:xxxxx} data

enter image description here

2
  • Do you try JSON.stringify(data)? Commented Mar 25, 2018 at 20:47
  • What do you want to be displayed in the textarea? Commented Mar 25, 2018 at 20:55

1 Answer 1

2

You can use JSON.stringify() to stringify your JSON data:

document.getElementById("info").value = JSON.stringify(personas); 
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much!!! it worked, I know it has to be super simple, appreciate your help Sebastian

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.