使用ajax v1.11.1进行表单提交,并将映像文件上传到数据库jsp servlet

时间:2017-11-01 09:30:54

标签: javascript ajax jsp

我使用此代码将图像上传到数据库但不成功。它没有将数据从jsp传递给servlet,控制台显示代码错误代码非法调用请帮我解决这个问题代码段在下面显示

错误代码:

Uncaught TypeError: Illegal invocation
       at e (jquery-1.11.1.min.js:4)
       at Vc (jquery-1.11.1.min.js:4)
       at Vc (jquery-1.11.1.min.js:4)
       at Function.m.param (jquery-1.11.1.min.js:4)
       at Function.ajax (jquery-1.11.1.min.js:4)
       at HTMLInputElement.eval (eval at <anonymous> (jquery-1.11.1.min.js:2), <anonymous>:95:36)
       at HTMLInputElement.dispatch (jquery-1.11.1.min.js:3)
       at HTMLInputElement.r.handle (jquery-1.11.1.min.js:3)

1.这是我的表格。

<form id="formAddEmployee" name="formAddEmployee" method="post" action="" autocomplete="on" enctype="multipart/form-data"> 

<td class="page_input_td">
                        <input  accept="image/*"  type="file" name="signature" id="signature" >
                    </td>

2.我的脚本文件

var formData = new FormData();
                if ($('#signature').length !== 0) {
                    formData.append('signature', $('#signature')[0].files[0]);
                }


var submitData = $.ajax({
                    url: "${pageContext.servletContext.contextPath}/AddEmployeeServlet",
                    type: 'POST',
                    data: {"employeeId": employeeId,
                        "name": name,
                        "nic": nic,
                        "contactNo": contactNo,
                        "email": email,
                        "address": address,
                        "designation": designation,
                        "department": department,
                        "formData": formData,
                        "formData": formData,
                        "status": status},
                    async: true,
                    cache: false
                });

0 个答案:

没有答案