日期:2014-05-16 浏览次数:20348 次
$("#btnAjaxGet").click(function(event) { var username = encodeURI(encodeURI($("#username").val())); var content = encodeURI(encodeURI("中国")); $.get("jqueryGet?username=" + username + "&content="+content+"×tamp=" + (new Date()).getTime(),function(data){ // decodeURI(data),后台没有经过java.net.URLDecoder.decode(tt, "UTF-8");就使用这个方法在解码一次,否则直接就是data $('#divResult').html(decodeURI(data)); }); });
PrintWriter out = response.getWriter(); response.setContentType("text/html;charset=UTF-8"); String info = ""; String tt = (String) request.getParameter("username"); String username = java.net.URLDecoder.decode(tt, "UTF-8"); String cc = request.getParameter("content"); String content = java.net.URLDecoder.decode(cc, "UTF-8"); info = "<div class='comment'><h2> " + tt + " </h2><p class='para'> " + cc + " </p></div>"; out.println(info); out.flush(); out.close();
$("#btnAjaxPost").click(function(event) { var username = encodeURI($("#username").val()); var content = encodeURI("中国"); //发送Post请求 $.get("jqueryGet" ,{ "username": username,"content":content},function(data){ $('#divResult').html(decodeURI(data)); }); });
$("#btnAjaxCallBack").click(function(event) { var username = encodeURI($("#username").val()); var content = encodeURI("中国"); //发送Post请求, 返回后执行回调函数. $.get("jqueryGet", { "username": username,"content":content}, function(responseText, textStatus, XMLHttpRequest) { responseText = " Add in the CallBack Function! <br/>" + decodeURI(responseText); $("#divResult").html(responseText); //或者: $(this).html(responseText); }); });
$("#btnAjaxXml").click(function(event) { var username = encodeURI($("#username").val()); var content = encodeURI("中国"); //发送Post请求, 返回后执行回调函数. $.get("jqueryGet", { "username": username,"content":content}, function(data) { var username = decodeURI($(data).find("comment").attr("username")); var content = decodeURI($(data).find("comment content").text()); var txtHtml = "<div class='comment'><h6>"+username+":</h6><p class='para'>"+content+"</p></div>"; $("#divResult").html(txtHtml); }); });
PrintWriter out = response.getWriter(); response.setContentType("text/xml"); String tt = (String) request.getParameter("username"); String username = java.net.URLDecoder.decode(tt, "UTF-8"); String cc = request.getParameter("content