xds ajax文件上传

发布于 2024-11-25 03:44:31 字数 1897 浏览 0 评论 0原文

希望有人可以帮助解决这个问题...

我正在构建一个可在许多地方使用的网络服务。

www.mywebservice.dev 和 www.mysite.dev 在我的本地计算机上设置以在野外复制真实的东西...

我正在使用动态脚本标记方法来允许我发布包含文件上传到第二个的表单服务器。

www.mysite.com 上的页面调用 www.mywebservice.dev (目前它只是回显 file_get_contents 调用)。

Web 服务返回,

<script script type="text/javascript">
$(function(){
    var $scrpt = $('<script><\/script>');
    $scrpt
        .attr('type' , 'text/javascript')
        .attr('src','http://www.mywebservice.dev/_assets/script/processEvent.js');
$('head').append($scrpt);

});
</script>
<form id=£event-form" ... >
.......
</form>

它被注入到页面中,没有任何投诉...

在 processEvent.js 内部是另一个包含 jquery.form 插件的调用(与上面的调用相同,但显然文件不同)和 ajax 调用:

$('#event-form').bind('submit',function(){
    $(this).ajaxSubmit({
        url     : 'http://www.nmssys.dev/webservices.php',
        type    : 'POST' ,
        data    : { ajax : 'true' , webservice : 'processEvent' } ,
        success : function( response ){
                      consloe.log( ' WOOHOO ' , response );
                  },
        error   : function( jqXHR , textStatus , errorThrown ){
                      console.log( ' BORKED ' , jqXHR , textStatus , errorThrown );
                  }
    });
    return false;
});

到目前为止一切顺利...

现在,当触发提交时,我得到一些奇怪的结果。

根据文档 jquery.form 将自动创建一个 iframe 来容纳文件上传。提交时,我从 firebug 获得以下信息...

控制台:

[jquery.form] state = uninitialized
[jquery.form] cannot access response document: Error: Permission denied to access property 'document'
[jquery.form] aborting upload... aborted
BORKED Object { aborted=1, status=0, more...} aborted server abort
[jquery.form] state = interactive

但是...

在请求条目下的 Net 选项卡中,响应是一个 JSONObj,如预期的那样,包含发送的帖子的详细信息...

有关获取此混蛋的任何帮助正确的将是最受欢迎的。

拥抱和亲吻所有人。

hoping someone can hel pon this one...

I am building a webservice to be consumed in many places.

www.mywebservice.dev and www.mysite.dev set up on my local machine to replicate the real thing in the wild...

I am using the dynamic script tag method to allow me to post a form including a file upload to a second server.

page on www.mysite.com makes a call to www.mywebservice.dev (at the moment its just echoing a file_get_contents call).

the web service returns

<script script type="text/javascript">
$(function(){
    var $scrpt = $('<script><\/script>');
    $scrpt
        .attr('type' , 'text/javascript')
        .attr('src','http://www.mywebservice.dev/_assets/script/processEvent.js');
$('head').append($scrpt);

});
</script>
<form id=£event-form" ... >
.......
</form>

which is injected into the page and no complaints...

Inside processEvent.js is another another call to include the jquery.form plugin (same as above call but diferenct file obviously) and an ajax call:

$('#event-form').bind('submit',function(){
    $(this).ajaxSubmit({
        url     : 'http://www.nmssys.dev/webservices.php',
        type    : 'POST' ,
        data    : { ajax : 'true' , webservice : 'processEvent' } ,
        success : function( response ){
                      consloe.log( ' WOOHOO ' , response );
                  },
        error   : function( jqXHR , textStatus , errorThrown ){
                      console.log( ' BORKED ' , jqXHR , textStatus , errorThrown );
                  }
    });
    return false;
});

So far so good...

Now when the submission is triggered I get some odd results.

According to the docs jquery.form will auto create an iframe to accomodate the file upload. When submiting I get the follwoing info from firebug...

Console:

[jquery.form] state = uninitialized
[jquery.form] cannot access response document: Error: Permission denied to access property 'document'
[jquery.form] aborting upload... aborted
BORKED Object { aborted=1, status=0, more...} aborted server abort
[jquery.form] state = interactive

HOWEVER...

In the Net Tab under the entry for the request the response is a JSONObj as expected with details of the post sent...

Any help on getting this fecker right would be MOST welcome.

Hugs and Kisses to all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

绮烟 2024-12-02 03:44:31

将响应数据返回到父页面的解决方案是使用 jquery postmessage 插件

The solution to getting response data back into the parent page was to use the jquery postmessage plugin

请恋爱 2024-12-02 03:44:31

好吧我有进步了!!!!

我一直在努力解决 iframetarget 选项,这是管理文件上传响应的方式。浏览器正在打开一个新选项卡,而不是将输出传递到指定的 iframe 中。

解决方案...动态创建 iframe 并将其附加到正文...

$('<iframe name="iframeUploader"/>')
    .prependTo('body')
    .attr({'id': 'responseTarget'})
    .css({'width':'1px','height':'1px','position':'absolute','left':'-9999px','top': '-9999px'});

并像这样修改提交:

$('#nms-event-form').live('submit',function(){
    $(this).ajaxSubmit({
        url          : 'http://www.mywebservice.dev/webservices.php' ,
        type         : 'POST' ,
        dataType     : 'xml' ,
        data         : { ajax : 'true' , webservice : 'processEvent' } ,
        success      : function( response , status ){
                           consloe.log( ' WOOHOO ' , response );
                       } ,
        error        : function( jqXHR , textStatus , errorThrown ){
                           console.log( ' BORKED ' , jqXHR , textStatus , errorThrown );
                       } ,
        complete     : function(){
                           console.log($('#responseTarget').html());
                       } ,
        iframeTarget : '#responseTarget'
    });
    return false;
});

CSS 只是防止 iframe 内容更改时可见性闪烁。

这正在传递来自远程服务器的响应,到目前为止,看起来所有数据和文件都已传递。

在 firebug 中,我现在得到:

[jquery.form] state = complete

并且响应数据可以在 iframe 中看到...

我已经向 ajaxSubmit 添加了一个完整的选项,但到目前为止它还没有触发(即使我在控制台中得到了状态 = 完整的消息)但我'我会解决这个问题并在收到后报告...

OK I have made progress!!!!

I was struggling with the iframetarget option which is the way to manage file uploads response. Browser was opening a new tab rather delivering output into a specified iframe.

The solution... create the iframe dynamically and append it to the body...

$('<iframe name="iframeUploader"/>')
    .prependTo('body')
    .attr({'id': 'responseTarget'})
    .css({'width':'1px','height':'1px','position':'absolute','left':'-9999px','top': '-9999px'});

and modify the submit like so:

$('#nms-event-form').live('submit',function(){
    $(this).ajaxSubmit({
        url          : 'http://www.mywebservice.dev/webservices.php' ,
        type         : 'POST' ,
        dataType     : 'xml' ,
        data         : { ajax : 'true' , webservice : 'processEvent' } ,
        success      : function( response , status ){
                           consloe.log( ' WOOHOO ' , response );
                       } ,
        error        : function( jqXHR , textStatus , errorThrown ){
                           console.log( ' BORKED ' , jqXHR , textStatus , errorThrown );
                       } ,
        complete     : function(){
                           console.log($('#responseTarget').html());
                       } ,
        iframeTarget : '#responseTarget'
    });
    return false;
});

the css simply prevents a flash of visibility when the iframe content changes.

This is delivering the response from the remote server and so far it looks like all data and files are passed.

In firebug I now get:

[jquery.form] state = complete

AND the response data can be seen in iframe...

I have added a complete option to the ajaxSubmit but as yet it is not firing (even though I get the state = complete mssg in console) but I'll over come this and report back when I get it...

旧竹 2024-12-02 03:44:31

文档说,如果您使用 iframetarget,那么它不会尝试处理响应。如果还能做到这一点就好了。

The docs say that if you use the iframetarget, then it doesn't attempt to handle the response. It'd be nice to still be able to do this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文