Over the past few days, I have been looking at the content in ASP. NET AJAX asynchronous calls to Web Services and webpage class methods, which is indeed very powerful, so that we can develop some ajax functions asynchronously. For details, go to Dflying Chen @ cnblogs's blog.
What I want to talk about today is that there is a pageload method in the background of the apsx page to load the function we want to execute for the first time. In fact, on the page, javascript also has a pageLoad method, the javascript code to be executed during page loading is easy to use. You can directly put it in <script>.
The Code is as follows:
Function pageLoad (){
// Call the methods in web service asynchronously
WebApplication1.WebService1. GetGenericEmployeeDictionary (onSucceeded );
}
We know that Microsoft has created many class libraries for us in ajax, many of which were originally class libraries in c # And are encapsulated in javascript, it is convenient for us to use in the development process.
For example, StringBuilder class
Var tableBuilder = new Sys. StringBuilder ("<table border = 1> ");
// Create a table heading row
TableBuilder. append (
"<Tr> <td> Id </td> <td> Name </td> <td> Email </td> <td> Salary </td> </tr>"
);
For (var key in result ){
Var employee = result [key];
// Create a table content row
Var rowString =
String. format (
"<Tr> <td >{0} </td> <td >{1} </td> <td >{2} </td> <td >{3} </td> </tr> ",
Employee. Id,
Employee. Name,
Employee. Email,
Employee. Salary
);
TableBuilder. append (rowString );
}
TableBuilder. append ("</table> ");
$ Get ("result"). innerHTML = tableBuilder. toString ();