ajax提交表单数据到后台失效问题怎么解决?

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加部门</title>
<script type="text/javascript">
function submitJson(formID, urlPath, message) {
    alert(1);
    $.ajax({
        url : urlPath,
        type : "post",
        data: $('#' + formID).serializeArray(),
        contentType : "application/x-www-form-urlencoded",
        success : function(data){
            alert(message);
            window.location.href="http://localhost:8080/admin" + data;
        },
        error : function() {
            alert("处理异常!");
        }

    });
}</script>
</head>   
<body>
    <form:form modelAttribute="department" id="form1"  method="post" >
    <fieldset>
        <legend>添加部门</legend>
        <p>
            <label>部门名:</label>
            <form:input path="dname" name = "dname" id="dname"/>
        </p>
        <p>
            <label>电话:</label>
           <form:input path="dtel" name = "dtel" id = "dtel"/>
        </p>
        <p>
            <label>描述:</label>
            <form:textarea path="describe" rows="5"/>
        </p>
        <p>
            <label>上级部门:</label>
            <form:select path="superdepartment"> 
                <option value="0"/>请选择上级部门
                <form:options items="${superdepartment }" itemLabel="dname" itemValue="id"/>
            </form:select>
        </p>
        <p id="buttons">
            <input id="reset" type="reset">
           <input id="submit" type="button" onclick="submitJson('form1','depart/addDepart', '添加成功!')" value="添加">
        </p>
    </fieldset>
</form:form>
</body>
</html>

上面那个弹窗1是测试用的能显示,ajax这个方法进不去为什么?

查看全部
weixin_44876820
肖潇晓枭逍
2019/04/29 18:08
  • html5
  • ajax
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

3个回复