ajax 页面发送post请求
来源:互联网 发布:知乎 三国武艺 编辑:程序博客网 时间:2024/05/06 02:20
ajax 发送url的请求,然后后台返回数据,前台根据返回数据进行处理~
<script type="text/javascript" src="js/jquery-1.4.1.min.js"></script> <script type="text/javascript"> $().ready(function () { $('#Login').click(function () { $.ajax({ type: "POST", url: "login.action", data: "sysUser.loginName=" + escape($('#username').val()) + "&sysUser.password=" + escape($('#password').val()), beforeSend: function () { $("#login").css("display", "none"); }, success: function (msg) { if (msg == "success") { //parent.tb_remove(); parent.document.location.href = "mainPage.action"; //如果登录成功则跳到管理界面 parent.tb_remove(); } if (msg == "failure") { alert('用户名或密码错误!'); } }, complete: function (data) { $("#login").css("display", "block"); }, error: function (XMLHttpRequest, textStatus, thrownError) { alert('模块加载异常!'); } }); }); }); </script>
后台代码
HttpSession session = (HttpSession) ServletActionContext.getRequest().getSession(); String ustr=ojbToJson(user); session.setAttribute("sysuser",ustr); ServletContext ContextA = session.getServletContext(); ContextA.setAttribute("globalSession", session); HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=utf-8"); try { PrintWriter out = response.getWriter(); out.write("success");// out.print("{success:true,'msg':'aaa'}"); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); }// this.setJsonStr("{success:true}"); }else{ ctx.put("user", null); HttpServletResponse response = ServletActionContext.getResponse(); try { PrintWriter pw = response.getWriter(); pw.write("failure");// pw.write("{failure:true,'msg':'aaa'}"); pw.flush(); pw.close(); } catch (IOException e) { e.printStackTrace(); }// this.setJsonStr("{failure:true}"); }
1 0
- ajax 页面发送post请求
- Ajax发送POST请求
- Ajax发送Post请求
- Ajax -- 发送 POST 请求
- Ajax发送post请求
- ajax 发送post请求
- Ajax发送POST请求SpringMVC页面跳转失败
- Ajax发送POST请求SpringMVC页面跳转失败
- ajax发送get、post请求
- ajax发送get、post请求
- Post方式发送Ajax请求
- AJAX发送POST、GET请求
- 原生ajax发送post请求
- Ajax post请求跳转页面
- POST方式发送ajax请求详解
- POST方式发送ajax请求详解
- POST方式发送ajax请求详解
- AJAX第二例(发送POST请求)
- JAVA中关于set()和get()方法的理解及使用
- Could not reload resource bundles java.lang.NoSuchFieldException: cacheList
- MVC5学习整理
- BZOJ-1011 遥远的行星 乱搞+估
- Error was tenMinuteCache Cache: The Disk store is not active.
- ajax 页面发送post请求
- java get set 方法有什么作用?
- getOutputStream() has already been called for this response
- java.lang.VerifyError
- java.lang.NocalssDefFoundError:oracle.jdbc.driver.T4CpreparedStatement
- Jmeter连接Mysql
- java.io.IOException: Negative seek offset
- 一个前端开发者的自我修养
- sql之left join、right join、inner join的区别