Javascript jQuery对话框文件上传
我试图从jQuery对话框窗口上传一个文件和一些字符串到我的php站点。 我用ajax发送字符串数据,但现在我读到我不能用ajax上传文件。获得这项工作的最佳解决方案是什么 HTML:Javascript jQuery对话框文件上传,javascript,php,jquery,ajax,jquery-file-upload,Javascript,Php,Jquery,Ajax,Jquery File Upload,我试图从jQuery对话框窗口上传一个文件和一些字符串到我的php站点。 我用ajax发送字符串数据,但现在我读到我不能用ajax上传文件。获得这项工作的最佳解决方案是什么 HTML: <div id="dialog" title="Quelle hinzufügen"> <table style="width:100%"> <tr> <form id= "file-form" action="upload
<div id="dialog" title="Quelle hinzufügen">
<table style="width:100%">
<tr>
<form id= "file-form" action="upload.php" method="post" enctype="multipart/form-data">
Datei zum Hochladen auswählen:
<input type="file" name="file-sel" id="file-select"/>
</form>
<tr>
<tr>
<p> Nicht bekannte Felder bitte leer lassen. </br></p>
</tr>
<tr>
<td>Titel</td>
<td>Person(en)</td>
<td>Jahr</td>
<td>Schlagworte</td>
<td>Veröffentlicht in</td>
</tr>
<tr>
<td><input type="text" name="titelin" id="titelin" value="" class="text ui-widget content ui corner-all"></td>
<td><input type="text" name="personin" id="personin" value="" class="text ui-widget content ui corner-all"></td>
<td><input type="text" name="jahrin" id="jahrin" value="" class="text ui-widget content ui corner-all"></td>
<td><input type="text" name="tagsin" id="tagsin" value="" class="text ui-widget content ui corner-all"></td>
<td><input type="text" name="verin" id="verin" value="" class="text ui-widget content ui corner-all"></td>
</form>
“但是现在我读到我不能用ajax上传文件。”-你可以用ajax上传文件。好吧,我错了,但是怎么做呢?你可以用ajax提交表单。例如,var formData=new formData('formid');$。ajax({url:'yourl',type:'POST',data:formData,success:function(data){alert(data);},});您的解决方案为我生成了一个错误:“uncaughttypeerror:非法调用”,在第9503行中引用了jquery文件。我刚刚为您提供了一个表单提交的ajax函数示例。要获得正确的代码,只需搜索如何使用ajax函数提交表单。您将很容易找到代码。
$(function() {
$( "#dialog" ).dialog({
autoOpen: false ,
width: 1500,
buttons: {
"Quelle hinzufügen": function() {
var out = [];
out.push(document.getElementById("titelin").value);
out.push(document.getElementById("personin").value);
out.push(document.getElementById("jahrin").value);
out.push(document.getElementById("tagsin").value);
out.push(document.getElementById("verin").value);
ajax(out);
},
Abbrechen: function() {
$( this ).dialog( "close" );
}
}
});
function ajax(info){
$.ajax({
type:"POST",
url:"quellenverzeichnis.php",
data: {output: info},
success: function(data){
alert("Quelle wurde hinzugefügt");
},
error: function(){
alert("fail");
}
});
};