在下面的代码中,有些情况下我可能会发现自己位于错误的页面上,然后在满足特定条件时重新路由。在这种情况下,我将如何从代码中调用$ http.get调用,并在继续执行脚本之前等待html源代码被恢复?在继续执行脚本之前从新网址检索html
function checkUrl(url, size, code) {
return $http.get(url).then(function(response) {
var html = response.data;
var listedPage = utility.countClass(html, 'product-tile');
if(listedPage > 1) {
url = getCorrectPage(html, code);
// this doesn't work, but I want to acquire the html of the newly acquired url
$http.get(url).then(function(response) {
html = response.data;
});
}
stockData.name = getProductName(html);
return stockData;
});
}
当你说“这行不通”,在*什么方式*它“不工作”?它如何失败? “url”不是你期望的那样吗?答案不是你期望的那样吗?还有别的吗? – David