admin管理员组文章数量:1344645
I seem not to get additionally data added to "formData".
First i add my input file:
var form = $('#uploadForm')[0];
var formData = new FormData(form);
var input = $("#uploadPhoto")[0];
//Add input file data to formData
formData.append(input.name, input.files[0]);
This works just fine.
And my PHP var_dump
after "ajax call" results:
array(1) {
["uploadPhoto"]=>
array(5) {
["name"]=>
string(5) "1.xls"
["type"]=>
string(24) "application/vnd.ms-excel"
["tmp_name"]=>
string(40) "..../tmp/phpmyn3E1"
["error"]=>
int(0)
["size"]=>
int(42799)
}
}
Now i'd like to add some extra data for passing on to the php script:
formData.append('usr', selectedUsr);
formData.append(input.name, selectedUsr);
formData.append('usr', 'usr: '+ selectedUsr);
When i now check my PHP var_dump, there is no "usr" data in array.
Why?
I seem not to get additionally data added to "formData".
First i add my input file:
var form = $('#uploadForm')[0];
var formData = new FormData(form);
var input = $("#uploadPhoto")[0];
//Add input file data to formData
formData.append(input.name, input.files[0]);
This works just fine.
And my PHP var_dump
after "ajax call" results:
array(1) {
["uploadPhoto"]=>
array(5) {
["name"]=>
string(5) "1.xls"
["type"]=>
string(24) "application/vnd.ms-excel"
["tmp_name"]=>
string(40) "..../tmp/phpmyn3E1"
["error"]=>
int(0)
["size"]=>
int(42799)
}
}
Now i'd like to add some extra data for passing on to the php script:
formData.append('usr', selectedUsr);
formData.append(input.name, selectedUsr);
formData.append('usr', 'usr: '+ selectedUsr);
When i now check my PHP var_dump, there is no "usr" data in array.
Why?
2 Answers
Reset to default 7When u append:
formData.append('usr', selectedUsr);
You cannot access the object with $_FILES['uploadPhoto']
Instead i access with $_POST
So my solution was:
//JS
formData.append('usr', selectedUsr);
//PHP
$usr = $_POST['usr'];
I think you are checking only $_FILES
, also check post data print_r($_POST)
本文标签: javascriptAppend data to formData objectStack Overflow
版权声明:本文标题:javascript - Append data to formData object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743702080a2524492.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论