在下面的代碼中,有些情況下我可能會發現自己位於錯誤的頁面上,然後在滿足特定條件時重新路由。在這種情況下,我將如何從代碼中調用$ 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