Pagination and deletion using Ajax (3)

Source: Internet
Author: User


Delete:

On the JSP page:

// When you click Delete

VaRDelhtmlbtn = getnode ("delbtn ");

// Register an event

Delhtmlbtn. onclick =Function(){

 

VaRIDS = "";

VaRDelchksnode = Document. getelementsbyname ("delchk ");

For(VaRI = 0; I <delchksnode. length; I ++ ){

If(Delchksnode [I]. Checked ){

IDS + = delchksnode [I]. Value + ",";

}

 

}

 

// Step 1: Create an XMLHTTPRequest object

VaRXMLHTTP = createxmlhttprequest ();

 

// Clear

Clearnodes (empshtmlnode );

 

XMLHTTP. onreadystatechange =Function(){

If(XMLHTTP. readystate = 4 ){

If(XMLHTTP. Status = 200 ){

// Obtain xmldocument

VaRXmldoc = XMLHTTP. responsexml;

// Obtain the tag

VaRRootnode = xmldoc.doc umentelement;

// Obtain all EMP element nodes in the XML file

VaREMPs = xmldoc. getelementsbytagname ("EMP"); // EMP id = "XXX"

// Obtain all child nodes in the EMP Node

For(VaR
I = 0; I <EMPs. length; I ++ ){

// Obtain a specific EMP:

VaREmpnode = EMPs [I];

// Create a row for EMP

VaRTr = Document. createelement ("TR ");

// Create the ID TD

VaRTD1 = Document. createelement ("TD ");

Td1.appendchild (document. createtextnode (EMPs [I]

. Getattribute ("ID ")));

Tr. appendchild (TD1 );

 

VaRElementnodes = empnode. childnodes; // name, sex, age

For(VaR
J = 0; j <elementnodes. length; j ++ ){

 

// Whether the node is an element node

If(Elementnodes [J]. nodetype = 1 ){

VaRTd2 = Document. createelement ("TD ");

Td2

. Appendchild (document

. Createtextnode (elementnodes [J]. firstchild. nodevalue ));

Tr. appendchild (td2 );

}

}

 

VaRDelchk = Document. createelement ("input ");

Delchk. setattribute ("type", "checkbox ");

Delchk. setattribute ("name", "delchk ");

Delchk. setattribute ("value", EMPs [I]

. Getattribute ("ID "));

Tr. appendchild (delchk );

Empshtmlnode. appendchild (TR );

 

}

 

// Call the page to create a Node object related to the page

Pagesnode (pageshtmlnode, rootnode );

}

}

}

 

// Step 2: Specify the Request Parameters

XMLHTTP. Open ("get", "./delservlet? IDS = "+ IDS

+ "& Timestamp =" +NewDate (). gettime (),
True);

// Step 3: send the request

XMLHTTP. Send (Null);

}

 

// Select all results

VaRChkshtmlnode = getnode ("Chk ");

 

// Registered event

Chkshtmlnode. onclick =Function(){

VaRDelchksnode = Document. getelementsbyname ("delchk ");

If(Chkshtmlnode. Checked ){

For(VaRI = 0; I <delchksnode. length; I ++ ){

Delchksnode [I]. Checked = "checked ";

}

}Else{

For(VaRI = 0; I <delchksnode. length; I ++ ){

Delchksnode [I]. Checked =Null;

}

}

}

The method for deleting the corresponding servlet is as follows:

Public voidDoget (httpservletrequest request, httpservletresponseresponse)

ThrowsServletexception, ioexception {

Request. setcharacterencoding ("UTF-8 ");

String IDs = request. getparameter ("IDS ");

// 1, 2, 3,

String values [] = IDs. Split (",");

System.Out. Println (values. Length );

For(IntI = 0; I <values. length; I ++ ){

Employeeservice. deletebyid (integer.Parseint(Values [I]);

}

Request. getrequestdispatcher ("/employeeservlet"). Forward (request, response );

}

 

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.