Create RSS aggregator based on PHP and AJAX

Source: Internet
Author: User
Imagine applying a simple HTML file to send a request to a server script, receiving a custom XML file based on the request, and then displaying it to the user without refreshing the browser! The author will discuss with you how to apply a simple HTML file to send a request to a server script and receive a custom XML file based on the request, then display it to the user without refreshing the browser! The author will discuss with you how to combine PHP and AJAX techniques in common Web application programs to create real-time data transmission without refreshing the browser.

Although the PHP language is used in this article, remember that any server language will work normally. To understand this article, I assume that you have a basic understanding of JavaScript, PHP, or a similar server-side language.

In this example, AJAX is used to send a request from an RSS feed to a required PHP object. This PHP object copies the feed on the local server and returns this path. The request object receives this path, analyzes it, and displays the data to the user in HTML format. This sounds like a lot of steps. actually, it only consists of four small files. The four small files were used to balance their specific strengths and make the processing of all systems very capricious.

Some readers may ask why you want to create a copy of the feed on the local server instead of simply analyzing the original feed. The reason is that the cross-domain restrictions imposed by xml http Request objects can be bypassed. Later, I will explain how to create this custom PHP object. but first, let's start from form creation.

   Create a form of pleading

The first thing you need to do is to include JavaScript and any CSS files that you may want to apply between your HTML head tags. I included a style table to implement the final layout of the aggregator and used a JavaScript file to send a request and analyze the feed:

<Link href = 'css/layout.css 'rel = 'stylesheet' type = 'text/css '/>
<Script src = 'JS/request. js'> </script>
Next, create a form that provides a request for an RSS feed you have selected. The form I created contains only one input field and a button to submit the request. The request query is a string consisting of the feed input value and a password that will be verified on the server side. as an example, I applied the following situation:
'Password = mypassword

This code makes a request each time a page is loaded. Therefore, if the page is refreshed, the existing feed string in the field will be begged during page loading. The following is an example of form data, along with some div labels used to display specific nodes of the analyzed feed:

<Body onload = 'javascript: makeRequest ('request. php? Request = 'document. feedForm. feed. value' password = mypassword'); '>
<Form name = 'feedform' method = 'post' action = 'javascript: makeRequest ('request. php? Request = 'document. feedForm. feed. value' password = mypassword'); '>
Enter a feed: <input type = 'text' name = 'feed' id = 'feed' size = '20'>
<Input type = 'submit 'name = 'submit 'value = 'add feed'>
</Form>
<Div id = 'logo '> </div>
<Hr/>
<Div id = 'copy'> </div>
<Div id = 'Details'> </div>
</Body>
The three div labels I created are logo, copy, and details. each of them has a style associated with it in the layout style sheet. They will be used when we analyze the feeds, but we need to first be able to access the feed we begged. This can be done by applying the PHP object I mentioned earlier.

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.