D
D
DrunkMaster2018-03-15 16:00:19
JavaScript
DrunkMaster, 2018-03-15 16:00:19

How to access a property of an object?

console.dir(obj);
console.dir(obj.status);
console.dir(obj['status']);

Answer:
5aaa6e321d698690035030.png
Full code:
function query(my){
        var obj = $.post('https://...', { var1: "1", var2: my}, function(go){
            return go;
        });
        console.dir(obj);
        console.dir(obj.status);
        console.dir(obj['status']);
    }

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fl3nkey, 2018-03-15
@DrunkMaster

If it's jQuery's $.post asynchronous method, you should work with the response in the callback. documentation .

$.post('https://...', { var1: "1", var2: my}, function(data) {
     console.log(data);
 });

Why do you see the finished object, but at the time of output to the console it was not ready? Article on this topic .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question