开发者

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;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜