-1

How can I access a propertie from this object?

An Object

I just want to get the 'responseText' propertie.

This object come from this function:

function freight(cep){

var response = $.post("./getFrete.php", {cep_destino: cep}, function(data){
    return data
});

console.log(response);

}

I've been trying to resolve it with "object_name['responseText']" and "object_name.responseText", but without success yet.

  • Please include code as text, not as an image. Also, please show what you've tried, and what research you've done into solving the issue yourself. [ask] is a good resource for knowing what is expected of questions on Stack Overflow. – Heretic Monkey Sep 27 '19 at 21:12
  • `object.responseText` just like accessing a property of any other object. – Barmar Sep 27 '19 at 21:12
  • Please consider taking the [tour](https://stackoverflow.com/tour) and reading [how to ask](https://stackoverflow.com/help/how-to-ask). Also please include a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Jesse Sep 27 '19 at 21:12
  • 1
    Given that that's an Ajax response, pretty sure that the real problem is trying to access the object before it exists. – JJJ Sep 27 '19 at 21:15
  • Ayup. https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call – JJJ Sep 27 '19 at 21:29

1 Answers1

0

Given an object named x with a property named y, we can access the property as x.y.

In your particular case, it looks like you have an object that represents the response to some sort of HTTP request. So, assuming that that object has been assigned to a variable named response, then you can access the statusText property as response.statusText.

response.statusText
Seth Holladay
  • 8,951
  • 3
  • 34
  • 43
  • You're right, it's an http request, but I'm getting de same mistake yet. Is returning "undefined". I'll edit my post end put my function there. – Tiego Araujo Sep 27 '19 at 21:26