Through code sample analysis, I will introduce to you how ajax implements partial page jumps and result returns. The specific content is as follows:
1. Submission with result return The process
is demonstrated here with a submit button. The HTML code is:
<input type="button" class="btn" value="提报" name="submit4" onClick="tibao();">
After clicking the report button, the jump to the action is processed through ajax. The JavaScript code is:
function tibao(){ var id=""; var URL = <select:link page="/smokeplan.do?method=Tibao&idset="/>+id; $.ajax({url: URL, type: "GET", success: function(result) { alert(result); } });}
After the action processing is completed, the returned result will be placed in the result, and a prompt message will pop up on the page; of course, the action jump here needs to be configured with xml.
The background Java class processing process is:
//提报 public void Tibao(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String idset=request.getParameter("idset"); CallHelper helper = initializeCallHelper("L_SmokeBoxtibaoWLDan", form,request, false); helper.setParam("bill_ids",idset); helper.setParam("personid",getPersonId(request)); helper.execute(); PrintWriter write = response.getWriter(); write.print(helper.getOutput("message")); write.close(); }
Here, the data is processed through a sql statement, a message is returned, and the information is printed to the page;
The result of the operation done here is reflected to the position corresponding to the response, so the stream belonging to the response is obtained instead of a new one.
That is to say, if I jump from there, my information will be returned there. So in js, you can use result to receive the returned result, and use alert to prompt.
How to use AJAX to achieve page jump
The sample code is as follows:
The ajaxAnywhere framework is used in the project to implement ajax. The effect is good and it is easy. Implemented, but the problem now is that even if the page achieves the effect, the business still needs to submit the form. In this case, even after clicking submit, it will still refresh the zone you defined. At this time, if you simply submit the form It’s not enough, the solution I took is:
Use js, a powerful BS project development tool, to customize a function to solve the above problem:
function doGuahao() { if(checkdata()) { if(document.form1.result_flag.value=="0") { return false; } else { if(document.form1.checktype.value=="danganhao") { form1.action = "<%=formAction%>"; form1.submit(); } if(document.form1.checktype.value=="xingming") { form1.action = parent.left.url2; form1.submit(); } if(document.form1.checktype.value=="shenfenzheng") { form1.action = "<%=formAction%>"; form1.submit(); } } } }
The above is the detailed content of Ajax tutorial page partial jump and result return. For more information, please follow other related articles on the PHP Chinese website!