Javascript 为什么表单数据没有使用serializeArray()接收表单字段

Javascript 为什么表单数据没有使用serializeArray()接收表单字段,javascript,php,jquery,html,form-data,Javascript,Php,Jquery,Html,Form Data,我不知道为什么表单字段没有通过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"&

我不知道为什么表单字段没有通过
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>

您不使用新FormData($((“includeExamform”)[0])的任何原因?请检查“网络”选项卡以查看发送的内容。@Barmar据我所知,有必要逐个字段追加,以便以后在php代码中识别和检索信息。我错了吗?如果
new FormData()
的参数是一个表单,它会自动填充表单中的所有输入字段。@Barmar在帖子中添加了控制台结果(我说它是空的)。正如您所看到的,只有文件通过发送。您不只是使用
新表单数据($((“includeExamform”)[0])
?请检查“网络”选项卡以查看发送的内容。@Barmar据我所知,有必要逐字段追加,以便以后能够在php代码中识别和检索信息。我错了吗?如果
new FormData()
的参数是一个表单,它会自动填充表单中的所有输入字段。@Barmar在帖子中添加了控制台结果(我说它是空的)。正如您所看到的,只有文件被发送通过。
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!');
                }
            }
    });
}
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
)