I am trying to get the response from ajax call and save it in another value but wont work
this is my code
x='go'
$.post("someurl",function(data){
x=data;
})
alert(x)//go
or this
jsFiddle
I am looking for a solution for this problem without storing the value in any HTML container
$.postis asynchronous – the callback will be executed later, after youralert(x)line.Try:
(No, there’s no other way around this – you’ll have to restructure your code accordingly. Don’t be tempted to try setting
asynctofalse, or you’ll end up with bigger problems).