1

After added file i get two errors:

   Blocked a frame with origin "http://host:8080" from accessing a frame with origin "http://host". Protocols, domains, and ports must match. ext-all.js:3922
   Uncaught SyntaxError: Unexpected token ) 

html code:

    buttons: [{
        text: 'Save',
        handler: function(){
            if(loadfile.getForm().isValid()){
                    loadfile.getForm().submit({
                        url: 'http://host/test/file-upload.php?path='+r.get('dtp'),
                        waitMsg: 'Сохранение фотографии...',
                        success: function(loadfile, o){
                        var data = Ext.decode(o.response.responseText);
                            Ext.Msg.alert('Success', data.msg);
                        },
                        failure: function(loadfile, o){
                        var data = Ext.decode(o.response.responseText);
                            Ext.Msg.alert('Failure', data.msg);
                        }
                    });
            }
        }
    },{
        text: 'Reset',
        handler: function(){
            loadfile.getForm().reset();
        }
    }]

php code:

     <?php
          $uploaddir = '/var/lib/tomcat6/webapps/test/upload/'.$_GET["path"];
          if (!is_dir($uploaddir))
             {
               mkdir($uploaddir, 0777);
             }
          $uploaddir.='/';
          if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir.$_FILES['userfile']['name']))
             {
               echo '("success": true, "msg": "Файл успешно сохранён.")';
             } else {
               echo '{"success": false, "msg": "Файл не сохранён!"}';
             }
     ?>

If set in html like this(without changed php code):

                        success: function(loadfile, o){
                            Ext.Msg.alert('Success', 'Success upload file');
                        },
                        failure: function(loadfile, o){
                            Ext.Msg.alert('Failure', 'Failure upload file');
                        }

i get only one error:

        Blocked a frame with origin "http://host:8080" from accessing a frame with origin "http://host". Protocols, domains, and ports must match. 

and all files uploading successful(for two examples).

ᄂ ᄀ
  • 5,669
  • 6
  • 43
  • 57
user15445
  • 146
  • 2
  • 20

2 Answers2

0

The error messages says it all, you're making a forbidden cross domain requests. "Protocols, domains, and ports must match." so host:8080 is considered a different domain than host.

Change your url to simply '/test/file-upload.php?path=' + r.get('dtp') and it should work.

See this question for more information and other possible solutions.

Your second error comes from the fact that your trying to decode something that is not JSON, nor Javascript (something like an error message), and that Ext.decode use eval on it.

Update

You've got another error in your PHP. Brackets should be curly in this line:

echo '("success": true, "msg": "Файл успешно сохранён.")';

You should use json_encode and PHP will take care of this for you:

$data = array('success' => true, 'msg' => '...');
echo json_encode($data);
Community
  • 1
  • 1
rixo
  • 23,815
  • 4
  • 63
  • 68
  • i set like '/test/file-upload.php?path=' + r.get('dtp') and i have only one error Uncaught SyntaxError: Unexpected token <. – user15445 Sep 27 '13 at 08:00
  • What is the content of the response body? You can see it in the net panel of the dev tools or output it in the console (`console.log(o.response.responseText)`). – rixo Sep 27 '13 at 08:06
  • "
    <?php
    $uploaddir = '/var/lib/tomcat6/webapps/test/upload/';//.$_GET["path"];
    if (!is_dir($uploaddir))
      {
        mkdir($uploaddir, 0777);
      }
    $uploaddir.='/';
    – user15445 Sep 27 '13 at 08:17
  • if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) { echo "success"; } else { echo "error"; } ?> " – user15445 Sep 27 '13 at 08:21
  • i undestand: my html http://host:8080/my.html but my php on http://host/my.php and in tomcat6(port 8080) no execute php, my php execute on apache only. – user15445 Sep 27 '13 at 08:23
  • Yes, that was the cause of the cross domain issue. Now, it also seems from the response that your PHP doesn't get executed. Try accessing your PHP directly from your browser and make it work from there before debugging the JS. – rixo Sep 27 '13 at 08:27
  • i think 'submit()' dont undestand what callback my php... my error after "doDecode = function(json) {return eval("(" + json + ")")}" – user15445 Sep 27 '13 at 08:36
  • any help me?zzzzzzzzzz – user15445 Sep 27 '13 at 10:56
  • Sorry but no. I pointed several problems, but you didn't make clear what you have understood, what you have fixed, and what is the problem now. I don't even know what is your code now, and I am not willing to play guessing. – rixo Sep 27 '13 at 11:24
  • ok, sorry. My problem have two error how in question. First error about my php starting on apache(html in tomcat6 without php support). Second error about loadfile.getForm().submit({success:...}) - dont undestand what returned my php(url: 'http://host/test/file-upload.php?path='+r.get('dtp')) - php return this: {"success": true, "msg": "success.."}. – user15445 Sep 27 '13 at 11:46
0

This is actually a bug in Extjs that has already been identified.

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

Please see the workaround in the post

cheftao
  • 179
  • 3
  • 15