jQuery return ajax result into outside variable

后端 未结 6 2026
栀梦
栀梦 2020-12-07 16:53

I have some problem using ajax.

How can I assign all result from ajax into outside variable ?

I google it up and found this code..

var return         


        
6条回答
  •  攒了一身酷
    2020-12-07 17:26

    I solved it by doing like that:

    var return_first = (function () {
            var tmp = $.ajax({
                'type': "POST",
                'dataType': 'html',
                'url': "ajax.php?first",
                'data': { 'request': "", 'target': arrange_url, 'method': 
                        method_target },
                'success': function (data) {
                    tmp = data;
                }
            }).done(function(data){
                    return data;
            });
          return tmp;
        });
    
    • Be careful 'async':fale javascript will be asynchronous.

提交回复
热议问题