关于Chrome扩展程序开发 popup.html页面通过jsonp的方式与服务端交互问题

传统web页面通过jsonp的方式与服务器端进行交互式代码为

$.getJSON("http://192.168.176.129:8000/login/?callback=?",{name:u_name,psw:u_psw},function(data){
                            
      if(data.msg =="True"){
            //success
      }else{
            //failed
      }
});

会报错误:

Refused to load the script 'http://192.168.176.129:8000/login/?name=test&psw=123456&callback=flightHandler' because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-eval'".

在manifest.json 文件中 配置permissions参数也不行

最后查看文档 进行跨域请求时 使用

var xhr = new XMLHttpRequest();
xhr.open("GET", "http://192.168.176.129:8000/register/?name="+username+"&psw="+password, true);
xhr.onreadystatechange = function() {
  if (xhr.readyState == 4) {
       var resp = JSON.parse(xhr.responseText);
       if(resp.msg =="True"){
              //success
       }else{
              //failed
       }
  }
}
xhr.send();

验证方法可行

另附 API文档

google文档:https://developer.chrome.com/extensions/overview

360翻译google:http://open.chrome.360.cn/extension_dev/overview.html