This time I will show you how ajax can make a partial page jump function. What are the precautions for ajax to make a partial page jump function? The following is a practical case, let's take a look.
Through code sample analysis, I will introduce to you the implementation of ajax to achieve partial page jump and result return. The specific content is as follows:1. Submission process with result return
A submit button is used to demonstrate here. The HTML code is:<input type="button" class="btn" value="提报" name="submit4" onClick="tibao();">
JavaScriptThe 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); } }); }
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(); }
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 easy to implement, 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 area you defined. At this time, If simply submitting the form is not enough, the solution I adopted is: Use js, a powerful BS project development tool, to self-define 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();
}
}
}
}
Recommended reading:
Ajax implements Loading effectJS implements ajax call background definition (with code)The above is the detailed content of How to make a partial page jump function in ajax. For more information, please follow other related articles on the PHP Chinese website!