ajax function returns [OBJECT OBJECT]

Asked

Viewed 580 times

-1

Good morning, you guys. I got a problem.

I set up a function to bring some results in the Onchange of a select via ajax

The problem is that this 'Qtde' input is printing the following msg [OBJECT OBJECT]

Who can tell me what’s wrong??

follows the code =>

function setqtde(obj)
 {
   var item = obj.value;
   $.ajax({
    url:BASE_URL+"estoque/pegaqtde",
    type:'GET',
    data:{valor:item},
    dataType:'json',
    success:function(json)
    {

      document.getElementById("qtde").value = json;
    }
  });
 }
  • json is an object. You have to use json.campo where field is the property that contains the quantity

  • It depends on jQuery’s content, it depends on what he did with the bakc-end, it depends on a lot of things to get the slightest sense of how to help you, until now it’s impossible/impossible to imagine the origin of the problem, I just tell you, the URL is returning a JSON as an answer and JSON cannot be printed as a string directly and it is not what you want, you clearly want something from the specific json, but the way this question is not able to guess anything. So give details.

2 answers

-1


Insert a console.log(json) on its return from json, as it is returned as an object, through the console it will be possible to see the attributes of the object. Thus, just access the desired returned object property as: json.propriedade

-1

It worked guys the property I needed to access was the amount

I put json.quantidade; it worked!

thanks a lot for the answers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.