• <bdo id='dovMR'></bdo><ul id='dovMR'></ul>
    <tfoot id='dovMR'></tfoot>
    <i id='dovMR'><tr id='dovMR'><dt id='dovMR'><q id='dovMR'><span id='dovMR'><b id='dovMR'><form id='dovMR'><ins id='dovMR'></ins><ul id='dovMR'></ul><sub id='dovMR'></sub></form><legend id='dovMR'></legend><bdo id='dovMR'><pre id='dovMR'><center id='dovMR'></center></pre></bdo></b><th id='dovMR'></th></span></q></dt></tr></i><div id='dovMR'><tfoot id='dovMR'></tfoot><dl id='dovMR'><fieldset id='dovMR'></fieldset></dl></div>

      <legend id='dovMR'><style id='dovMR'><dir id='dovMR'><q id='dovMR'></q></dir></style></legend>
    1. <small id='dovMR'></small><noframes id='dovMR'>

    2. 使用 FormData 对象,服务器收到一个空的 POST

      Using FormData object, the server receives an empty POST(使用 FormData 对象,服务器收到一个空的 POST)

      <small id='xWOjg'></small><noframes id='xWOjg'>

        • <bdo id='xWOjg'></bdo><ul id='xWOjg'></ul>

            <legend id='xWOjg'><style id='xWOjg'><dir id='xWOjg'><q id='xWOjg'></q></dir></style></legend>
              <tbody id='xWOjg'></tbody>

            <tfoot id='xWOjg'></tfoot>
            <i id='xWOjg'><tr id='xWOjg'><dt id='xWOjg'><q id='xWOjg'><span id='xWOjg'><b id='xWOjg'><form id='xWOjg'><ins id='xWOjg'></ins><ul id='xWOjg'></ul><sub id='xWOjg'></sub></form><legend id='xWOjg'></legend><bdo id='xWOjg'><pre id='xWOjg'><center id='xWOjg'></center></pre></bdo></b><th id='xWOjg'></th></span></q></dt></tr></i><div id='xWOjg'><tfoot id='xWOjg'></tfoot><dl id='xWOjg'><fieldset id='xWOjg'></fieldset></dl></div>
              1. 本文介绍了使用 FormData 对象,服务器收到一个空的 POST的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用 FormData 对象向我的服务器发送一个文件和一个文本变量.查看 Chrome 开发者工具中的网络选项卡,我可以看到文件和变量正在发送.但是,我在 $_POST 和 $_FILES 变量上尝试了 var_dump() ,两者都显示为空数组.这是我用于表单的代码:

                I'm attempting to send one file and one text variable to my server with the FormData object. Looking at the Network tab in Chrome's developer tools, I can see that the file and variable are being sent. However, I've tried var_dump() on the $_POST and $_FILES variables, and both are shown as empty arrays. Here's the code I'm using for the form:

                var image_upload = document.getElementById("image_upload");
                
                if(image_upload.value == '')
                {
                   alert("Please select a file to upload.");
                }
                else
                {
                   alert("in");
                   var ajaxHandler = new XMLHttpRequest();
                   var content = image_upload.files[0];
                   var formData = new FormData();
                   formData.append("type", "5");
                   formData.append("content", content)
                
                   ajaxHandler.onreadystatechange = function() {
                      if(ajaxHandler.readyState == 4)
                      {
                         alert(ajaxHandler.responseText);
                      }
                   };
                
                   ajaxHandler.open("POST", "newCard", false);
                   ajaxHandler.setRequestHeader("Content-type","multipart/form-data");
                   ajaxHandler.send(formData);
                }
                

                我已经尝试过在内容类型中使用和不使用charset=utf-8"的这段代码,但它似乎没有任何区别.这是怎么回事?

                I have tried this code with and without "charset=utf-8" in the content type, and it doesn't seem to make a difference. What's going on here?

                推荐答案

                从代码中删除 ajaxHandler.setRequestHeader("Content-type","multipart/form-data");.正确的 multipart/form-data 标头应包含边界字符串.如果您在 FormData 中添加文件,浏览器会自动设置该标题.

                Remove the ajaxHandler.setRequestHeader("Content-type","multipart/form-data"); from the code. The proper multipart/form-data header should contain boundary string. Browser automatically set that header, if you add file in FormData.

                这篇关于使用 FormData 对象,服务器收到一个空的 POST的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                When should use doctrine ORM and when zend-db-table?(什么时候应该使用学说 ORM,什么时候应该使用 zend-db-table?)
                Doctrine - self-referencing entity - disable fetching of children(Doctrine - 自引用实体 - 禁用获取子项)
                Doctrine 2, query inside entities(原则 2,实体内部查询)
                Complex WHERE clauses using the PHP Doctrine ORM(使用 PHP Doctrine ORM 的复杂 WHERE 子句)
                Doctrine - OneToMany relation, all result row doesn#39;t fetch in object(Doctrine - OneToMany 关系,所有结果行不获取对象)
                Doctrine and unrefreshed relationships(教义和未更新的关系)
                  <tbody id='JAWNq'></tbody>

                <small id='JAWNq'></small><noframes id='JAWNq'>

                  <i id='JAWNq'><tr id='JAWNq'><dt id='JAWNq'><q id='JAWNq'><span id='JAWNq'><b id='JAWNq'><form id='JAWNq'><ins id='JAWNq'></ins><ul id='JAWNq'></ul><sub id='JAWNq'></sub></form><legend id='JAWNq'></legend><bdo id='JAWNq'><pre id='JAWNq'><center id='JAWNq'></center></pre></bdo></b><th id='JAWNq'></th></span></q></dt></tr></i><div id='JAWNq'><tfoot id='JAWNq'></tfoot><dl id='JAWNq'><fieldset id='JAWNq'></fieldset></dl></div>

                • <tfoot id='JAWNq'></tfoot>

                  • <bdo id='JAWNq'></bdo><ul id='JAWNq'></ul>
                        1. <legend id='JAWNq'><style id='JAWNq'><dir id='JAWNq'><q id='JAWNq'></q></dir></style></legend>