This article is a newbieArticleIt is also a new handwritten article. Experts can filter it out. If you have read any comments, even if you mention it, the birds are willing to accept it ............. let's make a brick.
Updatepanel exists in Asp.net Ajax, but I don't want to use this. I thought of jquery and asked if I could implement the same function. So I searched for related articles, but someone asked me, the complete demo is not provided, but jquery can implement the load method.
Question: On the details page of an article ,【 Http://www.e6wa.com/Article/107.aspx ] When submitting a comment, I do not want to refresh the entire page. However, I want to refresh the comment section to display the comment I just posted. In this case, I want to refresh it to load data, I want to use jquery to implement partial refresh. How can this effect be achieved? Find relevant information and use jquery. Load. Next I will complete this article with a question and enter the topic: 1. Let's take a look at the jquery. Load () Syntax: (the original definition in jquery. API is as follows) Load (URL, Params, callback)Load a remote HTML content to a DOM node. Note: avoid using the loaded scripts script. use $. getscript instead. When any character is displayed, ie ignores all scripts. Return Value:Jquery
Parameters:
- URL (string): URL of the loaded HTML file
- Params (object): (optional) Key/value pair parameter sent to the server.
- Callback (function): (optional) function executed when data loading is complete.
Ii. Related Pages: (the two pages are in the same directory) 1. Article. aspx detailed article display page HTML page structure: <Input id = "topicid" type = "hidden" value = "<% = topicid %>"/> <Div id = "articlecontent"> </div> <Div id = "loadarticlereply"> </div> 2. articlereply. aspx comment loading page (display page) HTML page structure: A Repeater control to display comment content Load data in pageload and use the topicid passed by post Iii. RelatedCode: 1. When the article. ASPX page is loaded Step 1: Public int topicid; // define the variable; then, get the value of topicid when loading page_load, and bind the document Topicid = int. parse (request. querystring ["ID"]); // the request must be processed. Otherwise, many problems may occur. Here I will simply use it as a demonstration. Step 2: Load comments:
<SCRIPT type = "text/JavaScript">
Function loaddata (){
VaR tid = $ ("# topicid"). Val ();
$ ("# Loadarticlereply"). Load ("/articlereply. aspx", {"ID": TID}, function (){
$ ("# Loadarticlereply"). fadein ("slow ");
}
);
}
</SCRIPT> At this time, let's take a look at this loaddata function, take the ID serial number of the current article, load the comment address based on the div id, the ID serial number of the article, there is a display method and speed, Through the load URL and ID, we can go to the article Id serial number on the articlereply. ASPX page to get the relevant comment, and then present it in the DIV with the ID loadarticlereply.
Step 3: Load comments for the first time: In this case, what if I bind post comments when article. aspx is loaded for the first time ?? How can I call Js in CS ?? Of course, it is still in page_load of article. aspx. CS, If (! Page. ispostback) // load the comments for the first time and run the script
{
Clientscript. registerstartupscript (clientscript. GetType (), "myscript", "<SCRIPT> loaddata (); </SCRIPT> ");// Out-of-question questions: If you use the login control in ASP. net2.0 at the same time, there will be a small problem. At the end of this article, we will introduce
} Step 4: Submit and load comments when posting comments. [Please refer to this site for comments. Jquery Ajax introduction and simple examples in Asp.net ] 1. Submit a comment: function submitdata () {var id = $ ("# topicid"). Val ();
VaR commname = $ ("# txtnickname"). Val ();
VaR commemail = $ ("# txtemail"). Val ();
VaR commurl = $ ("# txturl"). Val ();
VaR comment = $ ("# articlecomment"). Val ();
$. Ajax ({
Cache: "false ",
Type: "Post ",
URL: "/postcomment. aspx ",
Data: "id =" + ID + "& name =" + commname + "& url =" + commurl + "& Email =" + commemail + "& comment =" + comment,
Success: function (MSG ){
If (MSG = "OK "){
Alert ("published successfully! ");
// 1. This is to refresh all data on the page
// Window. Location. Reload (true );
// 2. Refresh local data here Loaddata ();
}
Else if (MSG = "error "){
Alert ("failed to add! ");
}
}
});
} This article is basically over. Out-of-question questions: If it is used together with the login control in ASP. net2.0 at the same time, there will be a small problem, Cannot redirectLogin. aspxAt the end of this article, we will introduce
I have tried it for a long time and I don't know why. Then I thought about whether there was a problem in calling the method in script in article. aspx. I will find out the cause later: Registerstartupscript has an overloaded method. The last parameter indicates whether to add a Boolean value marked by the script. Clientscript. registerstartupscript (clientscript. GetType (), "myscript", "<SCRIPT> loaddata (); </SCRIPT> ", True ); Others: In
Yu's sky mentioned in this Article Http://feiyu.asgard.cn/article_156.html
I found it when I checked jquery source code and shared it with you. Add a space in the load URL and you will be able to follow the selector.
For example, I need to load the content of test.html, and just take the content with ID.
$ ("Body"). Load ("test.html # ");
Yes ^
Using this method, this article does not need to use the Repeater control to bind data. It may be better. If you think of it, don't forget to tell me. I hope this article will help you. Thank you.