在ExtJS 3.4中上传文件提交后出错

在ExtJS 3.4中上传文件提交后出错,extjs,Extjs,添加文件后,我收到两个错误: 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代码: buttons: [{

添加文件后,我收到两个错误:

   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代码:

    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代码:

     <?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": "Файл не сохранён!"}';
             }
     ?>
                        success: function(loadfile, o){
                            Ext.Msg.alert('Success', 'Success upload file');
                        },
                        failure: function(loadfile, o){
                            Ext.Msg.alert('Failure', 'Failure upload file');
                        }
我只得到一个错误:

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

所有文件上传成功(举两个例子)。

错误消息表明,您正在进行禁止的跨域请求。“协议、域和端口必须匹配。”因此
host:8080
被视为与
host
不同的域

将您的
url
更改为简单的
'/test/file upload.php?path='+r.get('dtp')
,它应该可以工作

有关更多信息和其他可能的解决方案,请参阅

您的第二个错误来自这样一个事实,即您试图解码的内容既不是JSON,也不是Javascript(类似于错误消息),而且
Ext.decode
使用
eval

更新

您的PHP中还有一个错误。此行中的括号应该是卷曲的:

echo '("success": true, "msg": "Файл успешно сохранён.")';
您应该使用
json\u encode
,PHP将为您解决这一问题:

$data = array('success' => true, 'msg' => '...');
echo json_encode($data);

这实际上是Extjs中一个已经被识别的bug


请参阅post

中的解决方法,我设置为'/test/file upload.php?path='+r.get('dtp'),我只有一个错误未捕获SyntaxError:意外标记响应主体的内容是什么?您可以在开发工具的网络面板中看到它,或者在控制台中输出它(
console.log(o.response.responseText)
)。“?php$uploaddir='/var/lib/tomcat6/webapps/test/upload/';/。$\u GET[”path“];if(!is_dir($uploaddir)){mkdir($uploaddir,0777)}$uploaddir.='/';if(move_上传的文件($\u FILES['userfile'.['tmp\u name'],$uploaddir.$_FILES['userfile']['name']){echo“success”}else{echo“error”;}?”我不理解:我的html,但我的php在tomcat6(端口8080)上不执行php,我的php只在apache上执行。