-1
function tinyurl() {
    jQuery.ajax({
        url: 'http://tinyurl.com/api-create.php?url=http://xxxxxxxxxxx/',
        dataType: 'script',
        success: function(response) {
            welcomemsg(response.id);
        }
    });
}

function namie() {
    jQuery.ajax({
        url: 'https://xxxxxx.com/names?user=random,
        dataType: 'jsonp',
        success: function(data) {
            welcomemsg(data);
        }
    });
}

function welcomemsg() {
    jQuery.ajax({
        url: 'https://xxxxx.com/posts?walmessage=Hello ' + data.name + ' your post has been posted '+ response.id +',
        dataType: 'script',
        success: function() {
        }
    });
}

我想得到tinyurlandnamie函数的响应,然后在函数中使用它们welcomemsg

我尝试使用参数但没有成功。

4

1 回答 1

2

使用由 . 返回的承诺$.ajax

var p1 = jQuery.ajax({url:'http://tinyurl.com/api-create.php?url=http://xxxxxxxxxxx/', dataType:'script'})

var p2 = jQuery.ajax({url:'https://xxxxxx.com/names?user=random', dataType:'jsonp'})

$.when(p1, p2).then(function (response, data) {
  welcomemsg(response[0], data[0]);
});

function welcomemsg(response, data){
  jQuery.ajax({
    url:'https://xxxxx.com/posts?walmessage=Hello ' + data.name + ' your post has been posted '+ response.id ,
    dataType:'script',
    success:function(){
    }
  });
}
于 2013-06-07T16:13:39.267 回答