肖潇晓枭逍 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才可以了。

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算