我想通过Ajax上传和映像到php脚本,但我有来自Firefox的这个例外!!
发出请求时出错:[例外..."' JavaScript组件没有名为的方法:"可用"'调用方法时:[nsIInputStream :: available]" nsresult:" 0x80570030(NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED)" location:" JS frame :: http://code.jquery.com/jquery-1.9.1.js :: .send :: line 8526"数据:没有]
这里是我的Ajax代码:
"Save": function() {
jQuery.ajax({
url: ajaxurl,
timeout:30000,
type: "POST",
data: {
'action':'update_mini',
'postdata': JSON.stringify(new FormData(document.getElementById("mini_form"))),//jQuery('#mini_form').serialize(),
'block': jQuery.urlParam('block')
},
enctype: 'multipart/form-data',
cache:false,
processData: false,
contentType: false,
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("An error has occurred making the request: " + errorThrown)
},
success: function(data) {
alert(data);
//jQuery("#mDialog").hide();
//jQuery( this ).dialog( "close" );
}
});
和Html表格代码:
<form id="mini_form" method="post">
<fieldset>
<label>Option Name :</label><br><input id="option" name="option" type="text"/>M<input id="m" name="m" class="minifield" type="text"/>P<input id="p" name="p" class="minifield" type="text"/><br>
Image: <input type="file" name="image" id="image" />
</fieldset>
</form>
感谢。
答案 0 :(得分:0)
请将您的参数放入formdata来尝试这个。
if (window.FormData) {
formdata = new FormData();
finput = document.getElementById("fileupload-input");
file = finput.files[0];
if (file && !!file.type.match(/image.*/)) {
if (formdata) {
formdata.append("image", file);
upSuccess = true;
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: formdata,
processData: false,
contentType: false,
async: false,
success: function(e){
if (e == 'error'){ //an error occurred in server side script
alert('An error occured while uploading the image.');
upSuccess = false;
}
}
});
if (upSuccess == false){
return;
}
}
}
}