I get a response from the POST method.
Inside I see the value, but after the POST method returns an empty value.
Why, hot fix this?
sample:
$.post('/news/add/', {parent: name, title: 'none'}, function(data){
new_id = data;
alert(new_id); //11
});
alert(new_id); //empty
Because you are making an asynchronous call the code is run in this order:
You can only use the value returned by your post inside the callback function.
The only other way to do this is to make the request synchronous. But that’s really not advised as it can lock out the browser waiting for the response.