jQuery:在Ajax请求中出现'Uncaught TypeError:Illegal Invocation' [英] JQuery: 'Uncaught TypeError: Illegal invocation' at ajax request

查看:175
本文介绍了jQuery:在Ajax请求中出现'Uncaught TypeError:Illegal Invocation'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此ajax函数将表单发布到特定的URL.它将到达所需的URL并进行处理,但是当它返回结果时却出现错误.

I am using this ajax function to post my form to a specific url .It is getting to the required url and processing but when it it return the result it is giving error.

     <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.

推荐答案

我认为问题出在ajax的数据部分.发送之前序列化表格

I think the problem is with the data part of your ajax. serialize the form before send

$.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);
    }

});

这篇关于jQuery:在Ajax请求中出现'Uncaught TypeError:Illegal Invocation'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆