我正在使用这个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>
But i am getting error illegal invocation while i return the result.
答案 0 :(得分:1)
我认为问题出在你的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);
}
});