我尝试使用post方法使用ajax上传图片,但我继续收到错误消息。当我这样做而没有ajax与作品。
HTML
<form onsubmit="" action="<%=editAction%>" method="post" enctype="multipart/form-data" name="form2" id="form2">
<table width="359" border="0" cellpadding="3" cellspacing="3" id="table">
<tr>
<td><strong> Name</strong></td>
<td><label for="name"></label>
<input type="text" name="name" id="name" autocomplete="off" /></td>
</tr>
<tr>
<td width="115"><strong>Area</strong></td>
<td width="223"><label for="area"></label>
<select name="area" id="area">
<option selected="selected">Public</option>
<option>Follows</option>
</select></td>
</tr>
<tr>
<td colspan="2"><input name="fileField3" type="file" multiple="multiple" id="fileField3" onchange="dwz_setEvent(this,'change')" onclick="dwz_setEvent(this,'click')" accept="image/*" capture="camera" /></td>
</tr>
<tr>
<td colspan="2"><input name="fileField2" type="file" multiple="multiple" id="fileField2" onchange="dwz_setEvent(this,'change')" onclick="dwz_setEvent(this,'click')" accept="image/*" capture="camera" /></td>
</tr>
<tr>
<td colspan="2"><label for="fileField"></label>
<input name="fileField" type="file" multiple="multiple" id="fileField" onchange="dwz_setEvent(this,'change')" onclick="dwz_setEvent(this,'click')" accept="image/*" capture="camera" />
<input name="user" type="hidden" id="user" value="1" />
<input name="time_group" type="hidden" id="time_group" value="2" />
<input name="ut" type="hidden" id="ut" value="new" />
<input name="uid" type="hidden" id="uid" value="7" /></td>
</tr>
<tr>
<td><input type="submit" name="button" id="button" value=" Upload" class="upload_button" /></td>
<td> </td>
</tr>
<tr>
<td><span style="width: 480px; margin: 0 auto; margin-top: 30px;"><img src="imgs/page_loader.gif" alt="" name="gif" width="46" id="gif" style="display: block; margin: 0 auto; width: 46px; visibility: hidden;" /></span></td>
<td> </td>
</tr>
</table>
</form>
AJAX
<script language="javascript">
$(document).ready(function(){
$("#form2").on('submit',function(event){
event.preventDefault();
data = $(this).serialize();
$.ajax({
type: "POST",
url: "upload_script.asp",
data: data,
success: function(data) {
$('#msg').html(data);
var result = $.trim(data);
if(result==="OK"){
$.mobile.changePage("#follow");
}
}
});
});
});
</script>
upload_script.asp
<%
'*********************************
'* *
'* INSERT RECORD AND UPLOAD *
'* http://www.dwzone.it *
'* *
'*********************************
server.ScriptTimeout = 5400
Dim RG_altVal, RG_columns, RG_Cong, RG_dbValues, RG_dbValuesTmp, RG_delim, RG_editCmd, RG_editQuery, RG_editQueryTmp, RG_emptyVal, RG_Ext, RG_Extensions, RG_fields, RG_FieldValueTmp, RG_FileDel, RG_FileExt, RG_formVal, RG_FS, RG_i, RG_L, RG_Len, RG_Max, RG_Name, RG_New, RG_newName, RG_Num, RG_Path, RG_Rec, RG_ret, RG_Save, RG_tableValues, RG_tableValuesTmp, RG_tst, RG_typeArray, RG_z, UploadStatus, NumFile
Dim RG_Connection, RG_editColumn, RG_recordId, Form, editAction, editRedirectUrl, RG_Files, RG_formName, UploadType, ParamVal, ParamList, MaxFieldNumber, TmpVal, x, y, Key, ProgressBar, newFileName
Dim tmpField_Name(), tmpValue_Name(), tmpField_Size(), tmpValue_Size(), tmpField_Thumb(), tmpValue_Thumb(), QtyRecord, TotalFileSize, valueToRedirectSend
Set Form = New ASPForm
Dim UploadID
UploadID = Form.NewUploadID
ProgressBar = ""
TotalFileSize = ""
editRedirectUrl = "a_upload_msg.asp"
RG_Connection = MM_viva_web_STRING
RG_editTable = "dbo.users_pics"
RG_Files = "C:\inetpub\wwwroot\vivaweb\usr_up_img\\;2;;;;1;pic;3;;;;0;;;;;1;fileField3|C:\inetpub\wwwroot\vivaweb\usr_up_img\\;2;;;;1;pic;3;;;;0;;;;;1;fileField2|C:\inetpub\wwwroot\vivaweb\usr_up_img\\;2;;;;1;pic;3;;;;0;;;;;1;fileField@_@_@2@_@_@0@_@_@0;;;80;0;;;80;0;_small;0;0|0;;;80;0;;;80;0;_small;0;0|0;;;80;0;;;80;0;_small;0;0@_@_@../"
RG_formName = "form2"
UploadType="Insert"
UploadStatus = ""
valueToRedirectSend = "seen"
NumFile = 0
if len(Request.QueryString("UploadID"))>0 then
Form.UploadID = Request.QueryString("UploadID")
end if
if (Request.QueryString <> "") Then
editAction = CStr(Request.ServerVariables("SCRIPT_NAME")) & "?" & Request.QueryString & "&UploadID=" & UploadID
else
editAction = CStr(Request.ServerVariables("SCRIPT_NAME")) & "?UploadID=" & UploadID
End If
Const fsCompletted = 0
If Form.State = fsCompletted Then
if Form.State = 0 then
Set ParamVal = CreateObject("Scripting.Dictionary")
tmp = split(RG_Files,"@_@_@")
ParamList = split(tmp(0),"|")
MaxFieldNumber = ubound(ParamList)
for x=0 to Ubound(ParamList)
TmpVal = Split(ParamList(x),";")
for y=0 to ubound(TmpVal)
Key = right("00" & cstr(x),3) & cstr(y)
ParamVal.add Key, TmpVal(y)
next
next
Form.Files.Save
RG_fieldsStr = "name|value|area|value|user|value|time_group|value|ut|value|uid|value"
RG_columnsStr = "name|',none,''|area|',none,''|email|',none,''|time_group|',none,''|upload_type|',none,''|up_user_id|none,none,NULL"
Form.Files.DataBaseInsert
response.write(getRedirect())
response.end
End If
ElseIf Form.State > 10 then
response.write "<br><Font Color=red>Some form error.<br>Error code: " & Form.State & "<br>Error List:<br>0 Form was successfully processed. <br>1 Request method is NOT post <br>2 Zero length request (there are no data in a source form) <br>3 Form is in a middle of process. <br>5 Initial form state <br>11 Boundary of multipart/form-data is not specified. <br>12 Unknown source form (Content-type must be multipart/form-data) <br>15 Client was disconnected before upload was completted.<br>16 Unexpected error from Request.BinaryRead method (ASP error).<br></Font><br>"
End If
function GetFolderName(str): GetFolderName = Ris : end function
function myGetFileName(str): myGetFileName = Ris : end function
%>
这是浏览器返回的错误消息
Some form error. Error code: 12 Error List: 0 Form was successfully processed. 1 Request method is NOT post 2 Zero length request (there are no data in a source form) 3 Form is in a middle of process. 5 Initial form state 11 Boundary of multipart/form-data is not specified. 12 Unknown source form (Content-type must be multipart/form-data) 15 Client was disconnected before upload was completted. 16 Unexpected error from Request.BinaryRead method (ASP error).
请帮助
答案 0 :(得分:0)
我建议您使用类似http://valums-file-uploader.github.io/file-uploader/的内容,因为$ .ajax不会使用enctype =&#34; multipart / form-data&#34;