Ajax application Case MSN Space

Source: Internet
Author: User
Tags comments functions
Ajax I have always admired the service of MSN Space, the album Service and Skin has always been a unique feeling. Domestic podcast, I prefer MSN space. Also possible, MSN space is not so much hype.

Well, that's it. A few days to study the MSN Space AJAX applications. Typical, its application is mainly embodied in: Network comments, fixed links, reference records, and custom lists on the log. Before you know about Ajax, you're always curious about how you get the data. Now, it's probably inkling.  As shown in the following figure.
For your Space home page, the JavaScript functions that you use to add comments, read comments, fixed links, and trackbacks are mainly used for: opensection (section, EntryID, Bnewcomment, Btriedpassportrefresh, barenewcommentsallowed), which uses the first parameter section to determine various types of operations, and then gets the data from the server, which is displayed in the corresponding Div floating layer.
The key code for obtaining data using AJAX is provided by JavaScript function getblogactivity (EntryID, item, Otherformfields, Btriedrefresh). The code looks like this:
function getblogactivity (EntryID, item, Otherformfields, Btriedrefresh)
{
var response = "";
var fexception = false;
Eval (' try {xmlhttp = new ActiveXObject (' Microsoft.XMLHTTP ');} catch (e) {xmlhttp = null;} ');
if (XMLHTTP!= null)
{
try{
xmlHTTP. Open ("POST", Blogjsposturl, false);
var stra = "handle=" + EntryID;
Stra + + "&blogitem=" + item;
Stra + + "&" + Blogjsblogpartparam;
Stra + = Otherformfields;
Xmlhttp.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
xmlHTTP. Send (Stra);
}catch (e) {
Fexception = true;
}
if (fexception) {
if (Btriedrefresh) {
Exception after trying passport refresh, stop this to avoid infinite loop
Response = "Error";
}else{
Build the Response-an iframe that'll load up and refresh Passport credentials
var timer = settimeout (Displaycontentloaderror (item, EntryID), 10000); Fail in 10s if not cleared
var iframestring = "<iframe src=\"/passportrefresh.aspx?id= "+ EntryID +" &function=get&timer= "+ Timer +" Item= "+ Item +" &formfields= "+ otherformfields.replace (/&/g,"%26 ") +"/> ";
var divid = "Pprefresh" + Item + EntryID;
if (document.getElementById (divID)) {
Response = iframestring;
document.getElementById (divid). Style.display = "None";
}else{
Response = "<div style=\" display:none\ "id=\" "+ divID +" \ ">" + iframestring + "</div>";
}
}
}else{
if (Xmlhttp.status!= 200) {
Response = "Error";
}else{
Response = Xmlhttp.responsetext;
}
}
}
return response;
}

It is easy to see that it uses the XMLHttpRequest synchronous request method. That's why the page needs to pause every time you click "Read comments." xmlHTTP. Open ("POST", Blogjsposturl, false); The blogjsposturl used in is defined on the home page of the space, and the remaining two functions are defined in the Blogjs.js file.

"Ajax Development detailed" in the "Simulation MSN Space" chapter will have more detailed elaboration.

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.