How Ajax realizes page local jump and result return _javascript skill

Source: Internet
Author: User

Through the code example analysis to introduce AJAX implementation page local jump and results returned, the specific contents are as follows:

1. Submit process with result return

Here is a submit button to demonstrate that the HTML code is:

<input type= "button" class= "btn" value= "" Name= "Submit4" onclick= "Tibao ();" >

After clicking on the quote button, you can use Ajax to implement the jump to action, JavaScript code:

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 process is completed, the returned results are placed in result, and the page pops up with the message; Of course, the action jump here needs to configure XML.

The background Java class processing process is:

Presentation 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 is a SQL statement to the data processing, return a message, and print the information to the page;

The result of the operation here is reflected to the response corresponding position, so get the stream belonging to the response, not the new one out.

That means I jump from there, and this information will go back there. So in JS you can use result to receive this return results, and with alert hint.

How to implement page jumps with Ajax

The sample code is as follows:

The project uses the Ajaxanywhere framework to achieve AJAX, the effect is good, and easy to implement, but now the problem is that even if the page has achieved results, the business still needs to submit the form, in which case, even if the click Submitted, it will still refresh your well-defined zone area, this time, If the simple submission of the form is not enough, I take the program 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 content is this article introduces how Ajax realizes the page partial jump and the result returns the entire content, hoped everybody likes.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.