AjaxのjQueryの上のデータパラメータにform.serializeする方法:さて、私は必要なのいるFormDataを取得し、私はこのような多くの情報とファイルmultiuploadアップローダーアップロードするフォームを持っている
<div class="col-md-4">
<div class="form-group">
<label class="control-label col-md-3">Location</label>
<div class="col-md-9">
<?php
$location = array(
"type" => "text",
"name" => "location",
"id" => "location",
"class" => "form-control"
);
echo form_input($location);
?>
<span class="help-block"></span>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label col-md-2">Warehouse</label>
<div class="col-md-10">
<?php
foreach ($tipe as $v):
echo "<label class='checkbox-inline'><input type='checkbox' name='tipe[]' value='$v->ID_CHECK_LIST'>$v->NAMA_CHECK_LIST</label>";
endforeach;
?>
<p class="help-block"></p>
</div>
</div>
</div>
<div class="col-md-12">
<div class="form-group">
<label class="control-label col-md-2">Image If Damage</label>
<div class="col-md-4">
<input type="file" multiple="" name="images[]">
<p class="help-block"></p>
</div>
</div>
をajaxを使ってそれらを送信する。私は$(form).serialized()を試していますが、$ _FILESは空ですので、FormDataクラスを使用します。しかし、FormDataはファイルを処理するだけで、別の入力は処理しません。ファイルと別の入力を処理するために、どのようにデータをajaパラメータに設定できますか?
これはとても感謝任意のヘルプのAjax jQueryの
$('#form').submit(function() {
$('#btnSave').text('saving...'); //change button text
$('#btnSave').attr('disabled', true); //set button disable
var url;
var formData = new FormData(this);
if (save_method === 'add') {
url = "<?php echo site_url('members/it/Request/ajax_add') ?>";
} else {
url = "<?php echo site_url('members/megumi/cek_list_wire_rod/ajax_update') ?>";
}
// ajax adding data to database
$.ajax({
url: url,
type: "POST",
data: formData,
processData: false,
contentType: false,
$('#form').serialize(),
dataType: "JSON",
success: function (data)
{
if (data.status) //if success close modal and reload ajax table
{
$('#modal_form').modal('hide');
reload_table();
} else
{
for (var i = 0; i < data.inputerror.length; i++)
{
$('[name="' + data.inputerror[i] + '"]').parent().parent().addClass('has-error'); //select parent twice to select div form-group class and add has-error class
$('[name="' + data.inputerror[i] + '"]').next().text(data.error_string[i]); //select span help-block class set text error string
}
}
$('#btnSave').text('Save'); //change button text
$('#btnSave').attr('disabled', false); //set button enable
},
error: function (jqXHR, textStatus, errorThrown)
{
alert('Error adding/update data');
$('#btnSave').text('save'); //change button text
$('#btnSave').attr('disabled', false); //set button enable
}
});
return false;
});
です。
私はあなたがENCTYPEを使用するために持っていると思う=フォーム –
でFORMDATA /マルチパート属性はい、私は持っていないが、ENCTYPEだまだ結果 –
:マルチパート/ FORMDATAが(ちょうど欲しかったです誰かが前のコメントからコピーしてペーストする前にタイプミスを指摘する) –