如何从 Chrome Web 应用程序内部使用 jQuery Ajax
我有一个带有以下清单的网络应用程序(扩展):
{
"name": "Porpington",
"version": "0.0.1.1",
"app": {
"launch": {
"local_path": "main.html"
}
},
"icons": {
"128": "mimsy.jpg"
},
"permissions":[
"http://*/*",
"tabs"
]
}
并且我有一个非常简单的 main.html (我使用 jquery 1.6.4)
<script src="jquery.js"></script>
<body>
<a href="javascript:getData()">getData</a><br/>
</body>
<script>
function getData(){
$.ajax({type: 'get',
mode: 'abort',
dataType: 'json',
url: 'http://localhost/confmart',
data: {},
success: function(res){
alert(res);
}
});
alert(3);
}
</script>
我在控制台中看到请求发出,我看到正确的响应(在控制台中) m 但由于某种原因,success
事件处理程序似乎没有被触发。
我做错了什么?
I have a web app (extension) with the following manifest:
{
"name": "Porpington",
"version": "0.0.1.1",
"app": {
"launch": {
"local_path": "main.html"
}
},
"icons": {
"128": "mimsy.jpg"
},
"permissions":[
"http://*/*",
"tabs"
]
}
and I have a very simple main.html (I use jquery 1.6.4)
<script src="jquery.js"></script>
<body>
<a href="javascript:getData()">getData</a><br/>
</body>
<script>
function getData(){
$.ajax({type: 'get',
mode: 'abort',
dataType: 'json',
url: 'http://localhost/confmart',
data: {},
success: function(res){
alert(res);
}
});
alert(3);
}
</script>
I see in the console the request goes out, I see the correct response (in the console)m but for some reason it looks like the success
event handler is not fired.
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
url:
对我来说看起来很可疑。向您的请求添加错误处理程序和超时:这可能相关,也可能不相关,但 ajax.
Your
url:
looks suspicious to me. Add an error handler to your request and a timeout:This may or may not be relevant, but there is no
mode:
listed in ajax.