根据chrome扩展API,如果设置了权限,则应允许使用XMLHttpRequest对象进行跨域调用:
扩展可以与其来源之外的远程服务器通信,只要它首先请求跨源权限即可.
我正在密切关注本教程,但下面的代码给出了一条错误消息:
XMLHttpRequest无法加载http://www.google.com/search?hl=en&q=ajax.原始chrome-extension:// bmehmboknpnjgjbmiaoidkkjfcgiimbo不允许使用Access-Control-Allow-Origin.
我不仅允许google.com的请求,而且要求任何网站但仍然无法通过.有人可以帮忙吗?
我的清单文件:
{
"name": "The popup",
"version": "0.1",
"popup": "popup.html",
"permissions": [
"http://*/*",
"https://*/*",
"https://www.google.com/*",
"http://www.google.com/*"
],
"browser_action": {
"default_icon": "clock-19.png",
"default_title": "This is title",
"default_popup": "popup.html"
}
}
Run Code Online (Sandbox Code Playgroud)
实际的电话:
function sendRequest() {
document.write("Sending request");
var req = new XMLHttpRequest();
req.open("GET", "http://www.google.com/search?hl=en&q=ajax", true);
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
alert(req.responseText);
document.write("OK");
}
}
};
req.send();
}
Run Code Online (Sandbox Code Playgroud) javascript ajax google-chrome xmlhttprequest google-chrome-extension
我试图使用AJAX来检索我想在用户端显示的推送通知的详细信息,但它还没有工作.
/*
*
* Push Notifications codelab
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES …Run Code Online (Sandbox Code Playgroud)