Send a File with Ajax into prototype
I'm trying to send a File to the Server without success. I have this :
HTML(it's not within a form ):
<td class="td_logo">
<input type="file" accept="image/*" multiple="false" name="realField" id="realField">
</td>
and i have a button who trigger the JS code.
JS
function sendRequest(url, firmObj){
new Ajax.Request(url,
{
method: 'post',
postBody: 'firmObj='+ Object.toJSON(firmObj),
onSuccess: function(){}
});
}
and the url call the PHP.
PHP
if( isset($_POST["firmObj"]))
{
$firmObj = json_decode($_POST["firmObj"]);
var_dump($firmObj);
}else{ echo "FAIL"; }
if($_FILES['realField']['name'])
{
print_r($_FILES['realField']['name']);
}else{ echo "FAIL";}
var_dump($firmObj)
jus开发者_运维百科t show me the file name and the other inputs in my table... but $_FILES['realField']['name']
is always false and shout "FAIL" out!!
How can i get the $_FILES filled with input data into prototype?
Thank you!!
Javascript cannot read local files (it would be a security nightmare) so AJAX doesn't really support uploads. Scripts like this one work by creating a form in a hidden iframe and submitting that.
精彩评论