【发布时间】:2016-06-04 17:29:41
【问题描述】:
基本上我想使用 jQuery 从 XML 和 JSON 提要返回数据,console.log 只有在两者都成功时才返回数据。
如果我在$.when 中注释掉getRoomFeed(),它将为XML 返回正确的responseText 对象,但是如果我将它们都留在其中,它会在我console.log(rateData) 时返回文档对象。为什么我不能从 JSON 和 XML 中提取数据并从两者中获取 responseText?为什么我在 $.when 中同时使用两个提要时会得到不同的结果?
查看附加的codepen并检查下面的控制台或代码,
function getRoomFeed() {
return $.ajax({
type: "GET",
url: "JSONURLHERE.json",
dataType: "JSON"
});
};
function getRates() {
return $.ajax({
type: "GET",
url: "XMLURLHERE.xml",
dataType: "XML"
});
};
$('#prop__selector').on('change', function() {
getPropCode = $(this).val();
$.when(getRoomFeed(), getRates()).then(function(roomData, rateData) {
console.log(roomData);
console.log(rateData);
});
});
http://codepen.io/benweiser/pen/gPNVmd/
我附上了图片,但不幸的是我不得不删除它们,因为我没有足够的声誉。
【问题讨论】: