jQuery. Assign JSON as a result to a variable

前端 未结 3 1186
走了就别回头了
走了就别回头了 2020-12-21 16:16

I use this helper function to receive JSON results for my requests:

function getData(url) {
    $.get(url,
         function(data) {
             response =          


        
3条回答
  •  心在旅途
    2020-12-21 16:43

    try this

    function getData(url) {
    var data;
        $.ajax({
            async: false, //thats the trick
            url: 'http://www.example.com',
            dataType: 'json',
            success: function(response){
               data = response;
            }
        });
        return data;
    }
    

提交回复
热议问题