我不知道为什么表单字段没有通过serializeAll()
函数提取,也没有到达被调用的php页面。
print_r($_FILES) // brings me data.
print_r($_POST/$_REQUEST/$_GET) // brings me NO data.
HTML 表单
<section id="featured">
<div class="container">
<div class="row">
<div class="col-lg-12">
<form id="includeExamform" method="post" class="validateform" name="send-contact">
<div class="title"><h3> <strong> CADASTRO EXAME </strong></h3></div>
<div id="select-patient">
Paciente: <button class="btn btn-theme btn-search margintop10 pull-left" type="button" onCLick="popupCenter('selecionaPaciente.php', 'selecionaPaciente', 750, 500);" >Pesquisar</button>
</div>
<br>
<div class="field-type-1">
Contactóloga: <input type="text" id="contactologa" size="50" maxlength="50" />
</div>
<br>
<div class="field-type-1">
Deficiencia: <input type="text" id="deficiency" size="50" maxlength="50" />
</div>
<br>
<br>
<strong><font color="Black">Longe </font></strong>
<div class="field-type-1">
D_Esf.: <input class="degree" type="text" id="longe_D_Esf" size="5" maxlength="5" /> D_CIL.: <input class="degree" type="text" id="longe_D_CIL" size="5" maxlength="5" /> D_Eixo a:<input class="degree" type="text" id="longe_D_Eixo" size="3" maxlength="3" />
</div>
<br>
<div class="field-type-1">
E_Esf.: <input class="degree" type="text" id="longe_E_Esf" size="5" maxlength="5" /> E_CIL.: <input class="degree" type="text" id="longe_E_CIL" size="5" maxlength="5" /> E_Eixo a:<input class="degree" type="text" id="longe_E_Eixo" size="3" maxlength="3" />
</div>
<br></br>
<strong><font color="Black">Perto</font></strong>
<div class="field-type-1">
D_Esf.: <input class="degree" type="text" id="perto_D_Esf" size="5" maxlength="5" /> D_CIL.: <input class="degree" type="text" id="perto_D_CIL" size="5" maxlength="5" /> D_Eixo a:<input class="degree" type="text" id="perto_D_Eixo" size="3" maxlength="3" />
</div>
<br>
<div class="field-type-1">
E_Esf.: <input class="degree" type="text" id="perto_E_Esf" size="5" maxlength="5" /> E_CIL.: <input class="degree" type="text" id="perto_E_CIL" size="5" maxlength="5" /> E_Eixo a:<input class="degree" type="text" id="perto_E_Eixo" size="3" maxlength="3" />
</div>
<br></br>
<div class="field-type-1" enctype="multipart/form-data">
<input name="userfile" type="file" id="userfile" class="filestyle" data-classButton="btn btn-primary" data-input="false" data-classIcon="icon-plus" data-buttonText="Escolha um arquivo">
</div>
<div>
Comentarios Adicionais: <textarea rows="7" id="remarks" class="input-block-level" placeholder="* Comentarios Adicionais..." ></textarea>
<br></br>
<p>
<button class="btn btn-theme btn-register margintop10 pull-left" type="button" onclick="return inserirExame(0);">CADASTRAR</button>
<span class="pull-right margintop20">* Por favor preencha todos os campos, obrigado!</span>
</p>
</div>
<br>
<br>
<br>
<br>
<br>
</form>
</div>
</div>
</div>
</section>
JS / JQuery (数据操作)
var fd = new FormData();
var other_data = $('#includeExamform').serializeArray();
$.each(other_data,function(key,input){
fd.append(input.name,input.value);
});
var file_data = $('input[type="file"]')[0].files; // for multiple files
for(var i = 0;i<file_data.length;i++){
fd.append("file_"+i, file_data[i]);
}
$.ajax({
type: "POST",
url: caminho+"/view/cadastroExame.php?acao=salvar",
timeout: 20000,
// enctype: 'multipart/form-data',
processData: false,
contentType: false,
data: fd,
success:
function(data){
if(jQuery.trim(data) == 'ok'){
alert('Sucess!');
$("#includeExamform")[0].reset();
$("#select-patient").html('Paciente: <button class="btn btn-theme btn-search margintop10 pull-left" type="button" onCLick="popupCenter(\'selecionaPaciente.php\', \'selecionaPaciente\', 750, 500);" >Pesquisar</button>');
// window.location = caminho+"/view/cadastroFornecedor.php";
}
else{
alert('Exam already registered!');
}
}
});
}
PHP (测试我执行并且没有表单字段数据)
print_r($_FILES);
print_r($_POST);
print_r($_REQUEST);
print_r($_GET);
if ( 0 < $_FILES['file']['error'] ) {
echo 'Error: ' . $_FILES['file']['error'] . '<br>';
} else {
move_uploaded_file($_FILES['file']['tmp_name'], 'uploads/' . $_FILES['file']['name']);
}
网络浏览器控制台 (结果)
Array
(
[file_0] => Array
(
[name] => PENDENCIAS IMA.txt
[type] => text/plain
[tmp_name] => /var/lib/openshift/5702831b7628e1462200001a/php/tmp/phpyvipCz
[error] => 0
[size] => 1270
)
)
Array
(
)
Array
(
[acao] => salvar
)