是否有可能伪造了jQuery的AJAX调用一个多/ form-data发布? [英] Is it possible to fake a multipart/form-data post with a jquery ajax call?

查看:151
本文介绍了是否有可能伪造了jQuery的AJAX调用一个多/ form-data发布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够张贴的multipart / form-data的消息发送回服务器。现在我知道,我不能直接与AJAX调用发送一个文件,我不想发送任何实际的文件。我想,这样它模拟了一个文件传输与的格式后,这是文件数据字符串,就好像它是该文件的内容和的test.txt 就好像它是文件名。

例如在后端(PHP)我想用回声$ _FILES ['UploadedFile的'] ['名称'] 测试.TXT

我想我得淤泥与正在发送的头,但不知道到底我有什么设置。我还以为我得区别对待假文件中的数据不是我送了Ajax调用数据的其余部分。现在我的AJAX调用是这样的:

  $。阿贾克斯({
            beforeSend:功能(REQ){
                req.setRequestHeader(接受,'');
                req.setRequestHeader(接受,$('#类型)VAL());
            },
            URL:$('#网址)VAL()。
            类型:$('#动词)VAL()。
            '数据':数据,
            MIMETYPE:多部分/表单数据,
            完整:功能(jqXHR,textStatus){
                VAR味精=数据:+转储(数据);
                味精+ =< BR />< BR />状态:+ jqXHR.status +(+ jqXHR.statusText + - + textStatus +)< BR />中;
                。MSG + = jqXHR.getAllResponseHeaders()代替(/ \ N /克,< BR />中);
                味精+ =---< BR />中+ jqXHR.responseText;
                $('#结果)HTML(MSG);
            }
        });
 

解决方案

您可以使用FORMDATA修补jQuery的, https://github.com/francois2metz/html5-formdata 看看这个问题,<一个href="http://stackoverflow.com/questions/5392344/sending-multipart-formdata-with-jquery-ajax">Sending多重/ FORMDATA与jQuery.ajax

I want to be able to post a multipart/form-data message back to the server. Now I know I can't send a file directly with an ajax call and I dont want to send any actual file. I want to format the post so that it simulates a file transfer with this is the file data string as if it were the file's contents and test.txt as if it were the file name.

For example on the backend (php) I want to use echo $_FILES['uploadedfile']['name'] and see test.txt.

I assume I'll have to muck with the headers being sent but not sure exactly what I have to set. I also assume I'll have to treat the fake file data differently than the rest of the data I'm sending over the ajax call. Right now my ajax call looks like this:

        $.ajax({
            beforeSend: function(req) {
                req.setRequestHeader("Accept", '');
                req.setRequestHeader("Accept", $('#type').val());
            },
            'url': $('#url').val(),
            'type': $('#verb').val(),
            'data': data,
            'mimeType': 'multipart/form-data',
            'complete': function (jqXHR, textStatus) {
                var msg = "Data: " + dump(data);
                msg += "<br /><br />Status: " + jqXHR.status + " (" + jqXHR.statusText + " - " + textStatus + ")<br />";
                msg += jqXHR.getAllResponseHeaders().replace(/\n/g, "<br />");
                msg += "---<br />" + jqXHR.responseText;
                $('#results').html(msg);
            }
        });

解决方案

you can use FormData to patch jquery, https://github.com/francois2metz/html5-formdata and see this question Sending multipart/formdata with jQuery.ajax

这篇关于是否有可能伪造了jQuery的AJAX调用一个多/ form-data发布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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