[英]Trying to send a response from express to jquery-iframe-transport
I'm trying to set up a simple file upload using jquery-ifram-transport and nodejs the problem is i keep getting the error caught SecurityError: Blocked a frame with origin "https://localhost:8081"
from accessing a frame with origin "serverURL". 我正在尝试使用jquery-ifram-transport和nodejs设置一个简单的文件上传,问题是我一直不断捕获错误SecurityError:阻止源为
"https://localhost:8081"
的帧访问源为帧“ serverURL”。 Protocols, domains, and ports must match. 协议,域和端口必须匹配。
Here is my clients ajax code from the client 这是我的客户来自客户端的ajax代码
var uploadXhr = $.ajax($scope.nodeSocketUrl + '/upload?tenant=qa',{
data: $(':text', form).serializeArray(),
files: $('#presentationFileUpload'),
type: 'POST',
iframe: true,
processData: false,
context: this
});
Here im just having a hard time getting this plugin to work with formidable I would like for a request to be sent back to the client like hey file has been uploaded something like this. 在这里,我只是很难让这个插件与强大的系统一起工作,我希望将请求发送回客户端,就像嘿文件已被上传这样。
form.on('end',function(){
res.header({'content-type': 'text/html'});
res.send('<html><textarea data-type="application/json">{"ok": true, "message": "Thanks so much"}</textarea></html>');
});
Anyone who knows how to sent back a request from express to a jquery-iframe-transport ajax request would be a huge help here. 任何知道如何将请求从express发送回jquery-iframe-transport ajax请求的人都将在这里提供巨大帮助。
Update Here are my current cors settings 更新这是我当前的cors设置
app.all('/*', function (req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Credentials', true);
res.header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, Content-Type, Authorization');
next();
});
Are you using Express? 您在使用Express吗?
Try this: 尝试这个:
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With");
next();
});
You need to enable CORS headers for it to work properly. 您需要启用CORS标头才能使其正常工作。
http://enable-cors.org/index.html http://enable-cors.org/index.html
Edit: 编辑:
Sometimes you need to configure your browser. 有时您需要配置浏览器。 Localhost behaves differently than actual domains.
Localhost的行为与实际域不同。
Start Chrome with these settings: --disable-web-security
使用以下设置启动Chrome:--
--disable-web-security
Read more about it here: 在此处了解更多信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.