Save data from AJAX request in variable (jQuery)
How can i get the data from a AJAX requ开发者_JAVA技巧est saved in a variable with jQuery?
var myvar;
$.ajax({
url: 'mything.php',
success: function(data) {
myvar = data;
}
});
use this
var myvar='';
$.ajax({
type:'post',
url: 'your url',
dataType:'text',
success: function(data) {
useReturnData(data);
}
});
function useReturnData(data){
myvar = data;
console.log(myvar);
};
How About This?
For Json Data:
var BaseConfig=$.ajax({
async:false,
url:'./config.php',
type:'get',
data:{'GetConfig':'YES'},
dataType:"JSON"
}).responseJSON;
And For Text Data:
var BaseConfig=$.ajax({
async:false,
url:'./config.php',
type:'get',
data:{'GetConfig':'YES'},
dataType:"TEXT"
}).responseText;
精彩评论