Using AJAX to read data from TXT

Source: Internet
Author: User

HTML code:

<div id= "News" ></div>

Txt:

[
{"id": "1", "News": "Notice: Facing Enterprise Social Security pain Point--why enterprise social insurance outsourcing trend", "url": "Http://www.baidu.com"},
{"id": "2", "News": "A good hr is like a good CEO", "url": "https://www.taobao.com/"},
{"id": "3", "News": "Content operations do not do well, and text editing no difference", "url": "https://www.taobao.com/"},
{"id": "4", "News": "The root of the product survival: Core function", "url": "https://www.taobao.com/"},
{"id": "5", "News": "What are the pitfalls of patent Application", "url": "https://www.taobao.com/"},
{"id": "6", "News": "Management software SaaS enterprise application, dial" cloud "See Day", "url": "https://www.taobao.com/"},
{"id": "7", "News": "Dream Capital", "url": "https://www.taobao.com/"}
]

Js:

<script type= "Text/javascript" >
$.ajax ({
Type: "POST",
ContentType: "Application/x-www-form-urlencoded;charset=utf-8",
URL: "Newsinfo.txt",
DataType: "JSON",
Success:function (data) {
var info= "<ul>";
I represents the index position in data, and N represents the object containing the information
$.each (Data,function (i,n) {
var str= "<li><a href= '" +n["url"]+ ">" +n["News"]+ "</a></li>";
INFO+=STR;
});
info+= "</ul>";
$ (' #news '). Append (info);
}
});
</script>

Using AJAX to read data from TXT

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.