我有两种形式.post到url进行处理,但是我.post不处理输入文件。
我尝试.serialize和.ajax都没有成功
我的两种形式:
<form name="PbxForm" id="PbxForm" action="index.php?mod=add_queues_details" method="post" enctype="multipart/form-data" class="myForms" >
...
<input type="file" class="" id="periodic_announce" name="periodic_announce" value="" style="width:100%">
....
<form action="index.php?mod=add_queues_details" method="post" name="PbxForm1" id="PbxForm1" class="myForms">
....
<select class="button" name="destination" id="destination" tabindex="2" data-id="0" style="width: 100%" required>
<option value="">== choose one ==</option>
<option value="extensions">Extensions</option>
<option value="queues">Queues</option>
<option value="operator">Operator</option>
<option value="forwarders">Forwarders</option>
</select>
....
site.js
$.post("index.php?mod=add_queues_details", $("#PbxForm, #PbxForm1").serialize(), function(){
window.location.href = "index.php?mod=queues";
});
我希望收到periodic_announce="test.wav"
,destination="extensions"
作为URL上的$_POST
值,但其中不包含periodic_announce
编辑
我进行了如下更改:
var fileName;
$('input[type="file"]').change(function(e){
fileName = e.target.files[0].name;
// alert('The file "' + fileName + '" has been selected.');
});
$("#queuesubmit").click(function() {
var file_data = $('#periodic_announce').prop('files')[0];
var form_data = new FormData();
form_data.append('periodic_announce', file_data);
$.ajax({
url: 'modules/queues/queues_exec.php', // point to server-side PHP script
dataType: 'text', // what to expect back from the PHP script, if anything
cache: false,
contentType: false,
processData: false,
data: form_data,
type: 'post',
success: function(php_script_response){
alert(php_script_response); // display response from the PHP script, if any
}
});
$.post("index.php?mod=add_queues_details", $("#PbxForm, #PbxForm1").serialize() + '&periodic_announce=' + fileName, function(){
window.location.href = "index.php?mod=queues";
});
});