Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs fileupload - cross-origin frame

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."}

Thanks in Advance!

like image 207
Anand Singh Avatar asked Mar 25 '14 06:03

Anand Singh


People also ask

Why did my ExtJS form submit fail?

Issue: ExtJS form.submit failed due to “accessing a cross-origin frame -> The file gets successfully uploaded however it ALWAYS returns FAILURE on form.submit Reason..."Blocked a frame with origin " http://localhost:57007 " from accessing a cross-origin frame." Solution: Don't use form.submit, use fetch instead. Show activity on this post.

Does cross origin frame error work in Edge 98+?

May 05 2022 12:50 AM - edited ‎May 05 2022 02:09 AM Started cross origin frame error after updating to Microsoft Edge 98+. It was working fine with an older version of Edge and also works in all versions of Google Chrome. Also tried to set same value to document.domain in both parent document and in iframe loaded document.

Is it possible to edit a file upload field in EXT?

A typical file upload field with Ext style. Direct editing of the text field cannot be done in a consistent, cross-browser way, so it is always read-only. The file path reported by the getValue method will


1 Answers

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

Description of the problem :

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.

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('');

Detail :

Please refer to : http://www.sencha.com/forum/showthread.php?136092-Response-lost-from-upload-Ajax-request-to-iframe-if-document.domain-changed

like image 183
cheftao Avatar answered Sep 29 '22 05:09

cheftao