我使用这个AJAX函数将我的表单发布到特定的URL。它是得到所需的URL和处理,但当它返回结果它给出错误。
<script type="text/javascript">
//var formm = "";
$("#UploadnForm").bind("submit", function () {
$('#UploadnForm input[type="submit"]').attr('disabled', true);
form = $(this);
$.ajax({
type: "POST",
cache: false,
url: $(this).attr('action'),
enctype: 'multipart/form-data',
data: new FormData(this),
success: function (data) {
alert("helo");
if (data.success == true) {
alert("The image is Uploaded");
}
},
error: function () {
alert(data.error);
}
});
});
</script>
但是我得到错误:
非法调用
返回结果
我认为问题出在ajax的数据部分。在发送
之前序列化表单$.ajax({
type: "POST",
cache: false,
url: $(this).attr('action'),
enctype: 'multipart/form-data',
data: $(this).serialize(),
success: function (data) {
alert("helo");
if (data.success == true) {
alert("The image is Uploaded");
}
},
error: function () {
alert(data.error);
}
});
编辑
$.ajax({
type: "POST",
cache: false,
url: $(this).attr('action'),
enctype: 'multipart/form-data',
data: new FormData(this),
processData: false,
contentType: false,
success: function (data) {
alert("helo");
if (data.success == true) {
alert("The image is Uploaded");
}
},
error: function () {
alert(data.error);
}
});