JSP_JSP+jquery使用ajax方式调用json的实现方法,本文实例讲述了JSP+jquery使用aja

test.jsp:Xg0码友部落

response.setContentType("application/x-json;charset=UTF-8");Xg0码友部落

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%response.setContentType("application/x-json;charset=UTF-8");String uid=request.getParameter("uid");int ret=0;String result = "{/"result/":" + ret + "}";out.print(result);%>Xg0码友部落

如{"result":0}Xg0码友部落

后台:Xg0码友部落

需要设置 :

复制代码 代码如下:Xg0码友部落

注意:返回json格式Xg0码友部落

<script type="text/javascript" src="https://www.xp.cn/jquery-1.5.1.min.js"></script><script type="text/javascript"> //test function test(uid) { if(confirm("确定该用户操作"+uid+"吗?")) { var date = new Date(); var param = {uid:uid}; jQuery.get("test.jsp?para=" + date, param,function(data){if(data != null){var result = data.result;//alert("data==="+data);if(result == 1){alert("操作失败");}if(result == 0){alert("操作失败。");//document.location.href = document.location;//window.location.reload();}} }); } }</script><a href="javascript:void(0);">submit</a>Xg0码友部落