Extjs fileuplaod - 跨原点帧 [英] Extjs fileuplaod - cross-origin frame

查看:262
本文介绍了Extjs fileuplaod - 跨原点帧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Extjs应用程序中有一个fileupload字段。我正在尝试通过以下代码将文件加载到服务器:

I have a fileupload field in my from in Extjs application. Where I am trying to load files to the server by following code:

var form = Ext.getCmp('ProcImpNewSugFileForm').getForm();
var fileNameStr = Ext.getCmp('ProcImpNewSugFileUpload').getValue().split("\\");
if(fileNameStr){
var filename = fileNameStr[fileNameStr.length-1];
if(form.isValid()){
    form.submit({
        url: '/PISRFileUploader.php',            
        waitMsg: 'Uploading your file...',                
        success: function (formPanel, action, result) {
            Ext.Msg.alert('Msg',"Success: "+action.response.responseText);
        },
        failure: function (formPanel, action, result) {
            Ext.Msg.alert('Msg',"Failure: "+action.response.responseText);
        }
    });
   }
}

但是当我尝试上传任何文件。该文件正在加载到服务器,但响应如下:

But when I try to upload any file. The file is getting loaded to the server but the response is coming like this:

    Failure: {success:false,message:"Blocked a frame with origin 'http://localhost' from accessing a cross-origin frame."}

感谢提前!

推荐答案

这是Uberdude在Sencha论坛中确定的Ext js错误。

This is a Ext js bug identified by Uberdude in the Sencha Forum.

问题描述

制作Ext.Ajax时。请求包含要上传的文件输入的表单,或手动将isUpload选项设置为true,而不是执行适当的Ajax请求Ext以标准HTML方式将表单提交到动态生成的隐藏。 json响应体然后从iframe中读出来创建一个伪装的Ajax响应。如果上传Ajax请求的页面已更改其document.domain属性,例如home.example.com中的一个页面包含来自static.example.com的资源,它希望使用javascript进行操作,而不会违反浏览器的同源策略,因此将其document.domain设置为example.com。如果home.example.com然后对home.example.com服务器的url进行上传Ajax请求,那么写入响应的iframe将其document.domain设置为home.example.com。因此,当home.example.com页面上的Ajax.request中的ExtJS代码尝试从iframe中提取文档正文时,它将被同源的策略阻止,并且传递给回调函数的响应将不正确地具有空responseText。

When you make an Ext.Ajax.request with a form containing a file input to be uploaded, or manually set the isUpload option to true, rather than doing a proper Ajax request Ext submits the form in the standard HTML way to a dynamically generated hidden . The json response body is then read out of the iframe to create a faked-up Ajax response. A problem arises if the page making the upload Ajax request has changed its document.domain property, e.g. a page at home.example.com includes resources from static.example.com which it wishes to manipulate with javascript without violating the browser's same-origin-policy, so both set their document.domain to "example.com". If home.example.com then makes an upload Ajax request to a url on the home.example.com server, the iframe into which the response is written will have its document.domain as "home.example.com". Thus when the ExtJS code within Ajax.request on the home.example.com page tries to extract the document body from the iframe, it will be blocked by the same-origin-policy and the response passed to the callback functions will incorrectly have empty responseText.

解决方法:
1.在进行上传请求时将document.domain传递给服务器。
2.在您的服务器响应中,将document.domain添加到响应文本/ html中。

Work Around : 1. Pass the document.domain to the server when making the upload request. 2. In your server response, add the document.domain in your response text/html.

response.setHeader('Content-Type','text / html');
response.write('document.domain ='+ params .__ domain +';');
response.write(JSON.stringify({msg:'Welcome'+ params.name}));
response.end('');

response.setHeader('Content-Type', 'text/html'); response.write('document.domain = "' + params.__domain + '";'); response.write(JSON.stringify({msg: 'Welcome ' + params.name})); response.end('');

详细信息:

请参阅:
http://www.sencha.com/forum/showthread.php?136092-Response-lost-from-upload-Ajax-request-to-iframe-if-document。域更改

这篇关于Extjs fileuplaod - 跨原点帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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