本文介绍了在ajax函数调用之后获取变量中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想进行2-3次ajax调用并检索各自的JSON数据,以便将所有JSON数据合并到一个最终的JSON对象中,然后对最终的JSON对象执行排序。



var json1 = [{countryName:Argentina,countryName:Bolivia}]

var json2 = [{countryName:Australia,countryName :纽埃}]



然后合并它



json1和json2的数据将来从正在进行ajax调用的功能。





可以有人帮助我。



我的代码///

I want to make 2-3 ajax calls and retrive their respective JSON data in order to combine all the JSON Data in one final JSON object then perform sorting on final JSON object.

var json1 = [{"countryName":"Argentina","countryName":"Bolivia"}]
var json2 = [{"countryName":"Australia","countryName":"Niue"}]

then merge it

the data of json1 and json2 will come from the function which is doing ajax call.


Could anybody help me.

my code///

var getCountries1 = function () {
var countries;
        $.ajax({
            url: "http://www.geonames.org/childrenJSON?geonameId=6255150",
            type: "post",
            asyn: true,
            success: function (data) {
                countries = data;

            }
        });
return countries;
//this is returning nothing as ajax call are asynchronous
    }

var getCountries2 = function () {
var countries;
        $.ajax({
            url: "http://www.geonames.org/childrenJSON?geonameId=6255151",
            type: "post",
            asyn: true,
            success: function (data) {
                countries = data;
            }
        });
return countries;
//this is returning nothing as ajax call are asynchronous
    }







$(function () {
   var json1 =  getCountries1();
   var json2 =  getCountries2();

});

推荐答案










这篇关于在ajax函数调用之后获取变量中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 03:50