在Chrome扩展中难住了jquery调用 [英] stumped on jquery call inside chrome extension

查看:329
本文介绍了在Chrome扩展中难住了jquery调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Chrome扩展中,我称之为:

  jsonPost = {
email:phil@demo.demo ,
password:demo,
content:$('#selected_text')。val(),
notification_type:$('#notification_type')。val(),
name:$('#notification_name')。val()
}
$ b $ .post('http:// localhost:3000 / api / create.json',jsonPost,
function(data){
console.log(type of data =+ typeof(data));
console.log(data in function =+ data);





这些数据会传递给服务器,但响应会丢失,在控制台
---数据类型=字符串
---数据在函数中=



所以出于某种原因,我没有收到回应。从浏览器中,我甚至试图做一个反对cnn.com并得到没有反应。



任何想法?



感谢

解决方案

您是否跑步ning成跨站点脚本限制?如果它在位于本地主机但不在扩展中的页面中工作,则可能需要请求Chrome访问扩展默认安全环境之外的内容。看看Google对为扩展程序请求跨网站权限的建议有帮助。


In my chrome extension I call this:

jsonPost = {
    email:"phil@demo.demo",
    password:"demo",
    content: $('#selected_text').val(), 
    notification_type: $('#notification_type').val(),
    name:$('#notification_name').val()
}

$.post('http://localhost:3000/api/create.json', jsonPost, 
        function (data) {
            console.log("type of data = " + typeof(data));
            console.log("data in function = " + data);
            }

The data makes it to the server. But the response is lost, in the console ---type of data = String ---data in function =

So for some reason I am not getting the response back. Works from the browser. I even tried doing a get against cnn.com and got no response.

any ideas?

thanks

解决方案

Are you running into cross-site-scripting restrictions? If it works in a page that's on "localhost", but not in the extension, it's probably that you need to ask Chrome's permission to access things outside the extension's default security context. See if Google's advice on requesting cross-origin permissions for an extension helps.

这篇关于在Chrome扩展中难住了jquery调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆