use*_*858 0 javascript firefox get
为什么这个网址提取不起作用?
实际上这个 GET 方法正在传递一些要存储的错误消息:
fetch('http://www.govtschemes.in/pushlo90.php?msg=alert-bid:0.120148336001477231576473857578-Please%20enter%20correct%20captcha', {
method: 'get'
}).then(function(response) {
}).catch(function(err) {
// Error :(
});
Run Code Online (Sandbox Code Playgroud)
但是,如果我在浏览器中输入相同的 URL ( http://www.govtschemes.in/pushlo90.php?msg=alert-bid:0.120148336001477231576473857578-Please%20enter%20correct%20captcha ) 就可以了。
WebExension 中的其他一些地方工作正常。
但不在另一个地方工作。此外,当我也进入 Firefox 控制台时,它也不起作用。它显示了一些“待定..”
此函数也显示相同的行为:
function ff_httpGetAsync(theUrl, callback, failed_cb) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
// console.log("Successfully downloaded the ajax page");
if (callback) {
if (xmlHttp.responseURL == theUrl) {
callback(xmlHttp.response);
} else {
console.log("diff response url received" + xmlHttp.responseURL);
}
}
} else {
// console.log("Got status =", xmlHttp.status);
}
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
console.log("Gettiy :" + theUrl);
xmlHttp.send(null);
}
ff_httpGetAsync('http://www.govtschemes.in/pushlo90.php?msg=alert-bid:0.120148336001477231576473857578-Please%20enter%20correct%20captcha', function() {
}, function() {});
Run Code Online (Sandbox Code Playgroud)
我检查了服务器。在这种情况下,后端 pushlo90.php 不会被调用。
不确定我的网址有什么问题?
小智 7
该结果告诉您承诺尚未得到答复。在某些情况下,在呈现页面之前非常快速地处理承诺时,它可能会起作用。
使用承诺,您基本上会说“向我保证您会这样做”。这个承诺要么被解决,要么被拒绝。在解决或拒绝之前,它始终处于待决状态。
在你的第一个函数中添加一些日志应该可以解释。
fetch('http://www.govtschemes.in/pushlo90.php?msg=alert-bid:0.120148336001477231576473857578-Please%20enter%20correct%20captcha', {
method: 'get'
}).then(function(response) {
console.log(response) //do something with response data the promise gives as result
}).catch(function(err) {
console.log(err)// Error :(
});
Run Code Online (Sandbox Code Playgroud)
如果您不想使用 .then(),请使用 async/await。
const functionName = async () => {
const result = await fetch(
"http://www.govtschemes.in/pushlo90.php?msg=alert-bid:0.120148336001477231576473857578-Please%20enter%20correct%20captcha",
{
method: "get"
}
);
console.log(result); //this will only be done after the await section, since the function is defined as async
};
functionName();
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
331 次 |
最近记录: |