• jquery ajax 无刷新页面


    jsp 

    <input type="button" class="button" value="保存" onclick="addCus()"/> &nbsp;&nbsp;

    javascript 

    function addCus(){
    var name = document.getElementById("customerName").value;
    if(name == ""){
    alert("提示:顾客姓名不能为空!");
    return false;
    }
    $.ajax( {
    url : "<%=request.getContextPath()%>/customer/findIsExistByName.action",
    type : "POST",
    cache : false,
    async : false,
    data : {
    "customerName" : name
    },
    dataType : "json",
    success : function(json) {
    /* alert(json[0].sex); json中有几条数据 ,json.length 就有几条数据,直接循环读取其中内容*/
    if(json.length != 0 || json != ""){
    alert("此顾客姓名已经存在!请重新输入");
    return false;
    }else{
    var conValue = confirm("提示:你正在添加顾客信息,是否确定?");
    if(conValue){
    with (document.getElementById("myform")) {
    method = "post";
    action = "<%=request.getContextPath()%>/customer/addCus.action";
    submit();
    }
    }
    }
    }
    });
    }

    struts_xml 

    <!-- 添加时候 ,判断顾客姓名是否存在 -->
    <action name="findIsExistByName" class="CustomerAction" method="findIsExistByName">
    <result name="success">/gk/gk_msg.jsp</result>
    <result name="error">/card/error.jsp</result>
    <result name="exception">/card/exception.jsp</result>
    </action>

    action  

    private String json;

    public String findIsExistByName(){
    try {
    List<CustomerInfo> cusList = customerService.getListCusByName(customerName);
    json = com.alibaba.fastjson.JSON.toJSONString(cusList);
    } catch (Exception e) {
    e.printStackTrace();
    this.addActionError("错误提示:对不起,系统暂时不能处理您<br>的请求,请稍候重试或与系统管理员联系!");
    return "exception";
    }
    return SUCCESS;
    }

    gk_msg.jsp 

    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>
    ${json}

  • 相关阅读:
    Linux MySQL的root无法登录数据库ERROR 1045 (28000)
    Linux 命令行初始化MySQL数据库
    Centos6、Centos7防火墙基本操作整理
    文本三剑客之awk
    加密类型、数据加密解密过程以及CA创建
    Centos7启动流程及systemd中Nginx启动配置
    Linux任务计划
    Linux进程管理
    IP地址简介及Linux网络管理工具
    Linux脚本
  • 原文地址:https://www.cnblogs.com/bailuobo/p/3665658.html
Copyright © 2020-2023  润新知