確定使用jQuery上傳插件,所以我想插入我的數據庫中的一些信息的信息是: 2隱藏的輸入,文本區域,輸入,文本,文件名和URL
<div id="Form" class="container1" style="display: none; width: 850px; height: 500px;">
<form id="fileupload" method="POST" enctype="multipart/form-data">
<span class='span' id=txt_lala></span>
<input type="hidden" name="anomalie" class="hide" id="anomalie" value="">
<input type="hidden" name="missionID" class="hide" id="missionID" value="<?php echo $_SESSION['mission_id']?>">
<fieldset class="fieldset1">
<table class="myTable" id="myTable">
<!--<input type="text" name="fait" id="fait" value="" class="text ui-widget-content ui-corner-all">!-->
<tr>
<td><label for="name">Recommandation:</label></td>
<td><textarea name="recommandation" id="recommandation" cols="50" ></textarea></td>
</tr><br>
<tr>
<td><label for="name">Constat:</label></td>
<td><textarea name="fait" id="fait" cols="50" ></textarea></td>
</tr>
</table><br>
<!-- Redirect browsers with JavaScript disabled to the origin page -->
<noscript><input type="hidden" name="redirect" value="https://blueimp.github.io/jQuery-File-Upload/"></noscript>
<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
<div class="fileupload-buttonbar">
<div class="fileupload-buttons">
<!-- The fileinput-button span is used to style the file input field as button -->
<span class="fileinput-button">
<span>Add files...</span>
<input type="file" name="files[]" multiple>
</span>
<button type="submit" class="start" >Start upload</button>
<button type="reset" class="cancel" >Cancel upload</button>
<button type="button" class="delete">Delete</button>
<input type="checkbox" class="toggle">
<!-- The global file processing state -->
<span class="fileupload-process"></span>
</div>
<!-- The global progress state -->
<div class="fileupload-progress fade" style="display:none">
<!-- The global progress bar -->
<div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100"></div>
<!-- The extended global progress state -->
<div class="progress-extended"> </div>
</div>
</div>
<!-- The table listing the files available for upload/download -->
<table role="presentation"><tbody class="files"></tbody></table>
</fieldset>
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-upload fade">
<td>
<span class="preview"></span>
</td>
<td>
<p class="name">{%=file.name%}</p>
<strong class="error"></strong>
</td>
<td>
<p class="size">Processing...</p>
<div class="progress"></div>
</td>
<td>
{% if (!i && !o.options.autoUpload) { %}
<button class="start" disabled>Start</button>
{% } %}
{% if (!i) { %}
<button class="cancel">Cancel</button>
{% } %}
</td>
</tr>
{% } %}
</script>
<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
<tr class="template-download fade">
<td>
<span class="preview">
{% if (file.thumbnailUrl) { %}
<a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
{% } %}
</span>
</td>
<td>
<p class="name">
<a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
</p>
{% if (file.error) { %}
<div><span class="error">Error</span> {%=file.error%}</div>
{% } %}
</td>
<td>
<span class="size">{%=o.formatFileSize(file.size)%}</span>
</td>
<td>
<button class="delete" data-type="{%=file.deleteType%}" data-url="{%=file.deleteUrl%}"{% if (file.deleteWithCredentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}>Delete</button>
<input type="checkbox" name="delete" value="1" class="toggle">
</td>
</tr>
{% } %}
</script>
</form>
和jQuery代碼是
jObjFormulaire.on("submit", function(){
var fait = $("#fait").val(),
anomalie = $("#anomalie").val(),
missionID = $("#missionID").val(),
recommandation =$("#recommandation").val();
/*var element = $("#pnewanomalie");
alert(element);*/
var filedata = document.getElementsByName("name");
var i = 0, len = filedata.files.length;
// On file add assigning the name of that file to the variable to pass to the web service
var aa = $("#new_anomalie");
// alert(aa.length);
if(aa.length){
// alert('autreAnomalie');
if($("#new_anomalie").val()!=''){
var autreAnomalie = $("#new_anomalie").val();
var status = 'NEW';
// alert(autreAnomalie);
}else{
var autreAnomalie ='';
alert("Veuillez donner le nom de la nouvelle anomalie.");
}
}
if (fait == ''){
alert("Champs commentaire Obligatoire ! Soumission du formulaire annulée.");
$(jObjFormulaire.data("checkbox")).prop("checked", false);
jObjFormDiv.dialog("close");
} else {
$.post("<?php echo $_SESSION['config']['businessappurl']?>index.php?display=true&module=Inspecteur&page=insertanomalie", {
fait1: fait,
anomalie1: anomalie,
missionID1: missionID,
autreAnomalie1:autreAnomalie,
status:status,
recommandation : recommandation
}, function(data) {
// $('#recommandation').val(data);
alert(data);
removeTableRow($("#myTable"));
$('#form')[0].reset(); // To reset form fields
location.reload();
// window.location.reload(true);
// $("#content").load('<?php echo $_SESSION['config']['businessappurl']?>index.php?display=true&module=Inspecteur&page=traitervolet&volet_id=<?php echo $_GET['volet_id']?>');
// $('#content').html(data);
});
//this.reset(); // To reset form fields
/*
* Comme le changement d'avis de l'utilisateur n'est pas géré,
* on peut l'empêcher de changer d'avis, mais ce n'est pas une bonne solution.
*/
$("#pnewanomalie").remove();
$(jObjFormulaire.data("checkbox")).prop("checked", true);
jObjFormDiv.dialog("close");
}
// Il faut bloquer la soumission traditionnelle
// du formulaire sinon la page est rechargée !
return false; // important !
});
使用[attr](http://api.jquery.com/attr) – 2015-02-05 16:12:19
並通過簡單的研究首先完成一些工作。 – 2015-02-05 16:13:08
你試過了什麼?在你的問題中沒有jQuery代碼顯示你的方法是什麼,並且HTML中沒有'span'元素。 – 2015-02-05 16:15:20