Ajax superposition (Ajax sends the data returned by Ajax)

Source: Internet
Author: User

Recently, I was working on a sign-in function of the personnel management system. First, I used the Department as the parameter and sent the parameter to the database using Ajax for query, then, the employee information is dynamically generated in the form of a table to the DIV on the returned page. The last column of the table is the sign-in button. At this time, I want to use jquery to continue obtaining the "sign-in" button that has been clicked, then, use ajax to send the data to the database check-in table and update the check-in table. Then, I set the ID attribute of each sign-in button to the employee ID returned by Ajax for the first time, and then use jquery to obtain the data again, how can this problem be obtained? I thought of adding the event selector to the tag, so I wrote the following code:

$ (Function (){

$ ("Tr input: button"). Click (){

$. Ajax ({
Type: "Post ",
URL: "page_helper.ashx ",
Data: "name = K & pid" + $ (this). ATTR ("ID "),
Success: function (HTML ){
$ ("# Returnhtml" ).html (HTML );
},
Error: function (){
Alert ("the server is busy. Please try again later! ");
}
});

}

});

However, after clicking the button, I found that the click event was not obtained, and the clicking button did not respond at all. When I used a browser to view the returned source code, I found that the HTML code returned by Ajax was not added to the page at all. What should I do this time? Later, I searched Baidu for half a day and said that the data returned by Ajax could not be viewed in the source code in the browser. Because it was asynchronous, I searched for the data for a day, and it was a big headache, so it was just evening, every time I encounter a big problem, I need to go to bed and try to implement it in my dream. On the one hand, I can rest and solve the problem. Generally, the problem will be answered the next day, can also be implemented.


The next morning, I woke up with no idea. I think this is a big problem. Is it impossible for me to implement it? Baidu almost didn't use two Ajax requests. In desperation, he posted a reward for help in the QQ space. The reward was a banquet for three days and three nights. Later, my great high school student finally gave me help, of course, it's not because of a reward that helps me, hahaha.

 

In my high school students, there is a live method in jquery that can obtain dynamically generated HTML code elements. Later, I knocked in the live method and saw three parameter events, data, function; view the help document of jquery.

Event: required. It specifies one or more events appended to an element. Multiple events are separated by spaces. Must be a valid event.

Data: (optional) additional data transmitted to the function.

Function: required. It specifies the function that runs when the current event occurs.


At this moment, I am suffering from drought and then I wrote the following code:

$ (Function (){

$ ("Tr input: button"). Live ("click", function (){


$. Ajax ({

Type: "Post ",


URL: "page_helper.ashx ",


Data: "name = JS & pid =" + $ (this). ATTR ("ID") + jsparam (),


Success: function (HTML ){


Alert (HTML );
},


Error: function (){


Alert ("the server is busy. Please try again later! ");
});
}
});

This miracle occurred. The button-Click Event returned by Ajax was obtained, and the following Ajax asynchronous process was also called successfully. That joy cannot be said.

If I give up this help, and encounter the same problem in the future, I may use the tag instead of the button to jump to another interface, which is too troublesome to operate, which of the following users will be disgusted when they see such an effect? Is it enough for a three-day, three-night banquet?


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.