javascript XMLHttpRequest:网络错误 0x2efd,由于错误 00002efd 无法完成操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15223683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd
提问by Bitsian
I am using socket.io for a windows azure project. Strangely the socket.io server starts when i just deploy the web role but when i deploy the whole cloud project, the socket.io server doesnt start and i get this error -
我正在将 socket.io 用于 windows azure 项目。奇怪的是,socket.io 服务器在我刚刚部署 web 角色时启动,但是当我部署整个云项目时,socket.io 服务器没有启动,我收到这个错误 -
"SCRIPT7002: XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd."
I have absolutely no idea what that means. Can anyone help me out on this one? I have been banging my head about it all day.
我完全不知道这意味着什么。谁能帮我解决这个问题?我整天都在为这件事头疼。
SocketClient.html
SocketClient.html
<script>
var socket = io.connect('http://127.0.0.1:4001');
socket.on('news', function (data) {
console.log(data);
});
$(function () {
$("#sendresponse").bind("click", function () {
socket.emit('server', 'Hello World');
});
}
);
</script>
App.js
应用程序.js
var app = require('express')(), server = require('http').createServer(app), io = require('socket.io').listen(server);
server.listen(4001);
app.get('/', function (req, res) {
res.sendfile(__dirname + '/index.html');
});
io.sockets.on('connection', function (socket) {
socket.emit('news', { hello: 'first time connect' });
socket.on('server', function (data) {
console.log(data);
socket.emit('news',"hello");
});
});
采纳答案by Bitsian
Turned out that the App.js script was not running when i deployed the cloud project, i.e the iisnode handler which i had put in my web.config wasnt doing its job when the whole cloud project was deployed. After going through this articlei found out that i had to put some files in my bin folder of web role namely - ChangeConfig.ps1,download.ps1,node.cmd,setup_web.cmd. you can generate these files when you go through that article. And finally you have to put this code in your ServiceDefinition.csdef
结果发现,当我部署云项目时,App.js 脚本没有运行,即在部署整个云项目时,我放在 web.config 中的 iisnode 处理程序没有完成它的工作。在阅读完这篇文章后,我发现我必须将一些文件放在我的 web 角色的 bin 文件夹中,即 - ChangeConfig.ps1,download.ps1,node.cmd,setup_web.cmd。当您阅读那篇文章时,您可以生成这些文件。最后你必须把这段代码放在你的 ServiceDefinition.csdef 中
<Startup>
<Task commandLine="setup_web.cmd > log.txt" executionContext="elevated">
<Environment>
<Variable name="EMULATED">
<RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
</Variable>
<Variable name="RUNTIMEID" value="node;iisnode" />
<Variable name="RUNTIMEURL" value="" />
</Environment>
</Task>
</Startup>
And voila!! It works like a charm. You would still have to start the socket.io server by running 127.0.0.1/App.js on browser. I am still looking at how to start App.js programattically.
瞧!!它就像一个魅力。您仍然需要通过在浏览器上运行 127.0.0.1/App.js 来启动 socket.io 服务器。我仍在研究如何以编程方式启动 App.js。