Ajax Overlay (Ajax return data is emitted with Ajax) sample code _ajax related

Source: Internet
Author: User
Recently in the Personnel Management system of a check-in function, first of all, the department as a parameter, the parameters of Ajax sent to the database to query, and then dynamically generated in tabular form of employee information to the return page of the Div, the final column of the table is the Check-in button, then I want to use jquery continue to get clicked "check-in" button, and then use AJAX to send the data to the Database check-in table, update the check-in table, so I will each check-in button ID attribute set to the first Ajax return of each employee information of the work number, again with jquery access, how to get it? Thought of the tag plus event selector, and then wrote the following code:
Copy Code code as follows:

$ (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 ("Server busy, please try again later!") ");
}
});
}
});

But then click to find no click on the event, click the button does not respond, when I use the browser to view the return of the source code, found that the original Ajax returned HTML is not added to the page, this time how to do? Later went to Baidu search for a half-day, all said that the data returned by Ajax can not be viewed in the browser to the source code, because it is asynchronous, the search for a day, the head is big and painful, so on the night, each encounter big problems, hurriedly sleep, in the dream to achieve methods, so on the one hand can rest, on the other hand can also solve the problem, Usually the next day the question will have the answer, also can achieve.

The next morning woke up, the idea is not, I think this should be a big problem, is not what I want to achieve it? Baidu almost no use two times Ajax request, but under the QQ space released a reward for help, a reward is a fete three days, then finally my great high school students gave me help, of course, not because of a reward to help me, hahaha.

As high school students say, there's a live method in jquery that gets dynamically generated HTML code elements, and then I knock the live method in, look at three parameters event,data,function, and then look at the help documentation for jquery.
Event: Required, specify one or more events attached to the element, separated by a space of multiple events. Must be a valid event.
Data: Optionally, specify additional data to be passed to the function.
Function: required to specify the functions to run when the current event occurs.

At this time I am at this time of drought, then write down the following code:
Copy Code code as follows:

$ (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 ("Server busy, please try again later!") ");
});
}
});

The miracle came, Ajax returned the button click event was fetched, the following Ajax asynchronous process is also called success, that kind of joy can not say.
If I give up this turn, later encountered the same problem, I may change a way of thinking, will use a label instead of button, jump to another interface, the operation is too troublesome, which users see this effect will be extremely disgusting, students such a help three days three nights of fete enough?
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.