I am try to get the json response from a url. Below is the php code which I am requesting to:
if($_POST){
header('Content-type: application/json');
echo '{"hello":"world"}';
}
Below is the javascript I wrote:
$('#site').change(function(){
var result;
$.ajax({
url: "URL",
data: { param:value },
type: "POST",
dataType: "json",
success: function(data,textStatus,jqXHR) {
alert(data['hello']); //output: world
result = data;
},
});
alert(result['hello']); //output: nothing (didn't alert)
alert(result); //output: undefined
});
So, my question is how can I assign the data to the result? Thanks.
Edit: My question is duplicated with How to return the response from an AJAX call?