肖潇晓枭逍 2019-04-29 18:08 采纳率: 100%
浏览 489

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这个方法进不去为什么?

  • 写回答

3条回答

  • ffmmqiang 2019-04-29 19:49
    关注

    你的 url : urlPath, 这个要带ip,端口,uri才可以了。

    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用