Ajax instant Update get data combined with Ajax JS reference use of course need to build local environment and create PHP

Source: Internet
Author: User

<! DOCTYPE html>
<meta charset= "UTF-8";
<title></ Title>
<script src= "13ajax.js" ></SCRIPT>
<script>
Window.onload=function () {
var Obtn=document.getelementbyid (' btn1 ')
Obtn.onclick=function () {
SetInterval (function () {
Ajax (' Get ', ' Getdata.php ', ', function (data) {
var data=json.parse (data);
var Oul=document.getelementbyid ("Ul1")
Var Html= '
for (var i=0;i<data.length;i++) {
html+= ' <li><a href= ' "> ' +data[i].title+ ' </a>[ <span> ' +data[i].data+ ' </span>]</li> '
}
oul.innerhtml=html;
}
},4000)
}
}
</script>
<body>
<input type= "button" value= "Get" Id= "Btn1",
<ul id= "UL1";
</ul>

<!--Ajax ({
Type: ' Get ',
URL: ' getdata.php ',
Data: ",
Success:function () {
}
})--
</body>

getdata.php Content

<?php

Header ("content-type:text/html;charset= ' Utf-8 '");
error_reporting (0);

$new = Array (
Array (' title ' = ' + ' meets Chinese and foreign correspondents at Xiamen International Conference Center ', ' data ' = ' 2017-9-19 '),
Array (' title ' = ' = ' Yesterday, BRICS leaders Xiamen meeting successfully concluded ', ' data ' = ' 2017-2-12 '),
Array (' title ' = ' China held ' dialogue with emerging markets and developing countries ', ' data ' = ' 2017-7-12 '),
The array (' title ' = ' + ' sends a strong signal of deepening cooperation and global development ', ' data ' = ' 2017-6-21 '),
Array (' title ' = ' + ' together out of an innovative, coordinated, green, open ', ' data ' = ' 2017-10-21 '),
Array (' title ' = ' = ' next year, South Africa will be the BRICS presidency ', ' data ' = ' 2017-9-12 '),
Array (' title ' = ' + ' together to drive the BRICS partnership to move forward ', ' data ' = ' 2017-9-3 '),
Array (' title ' = ' = ' next year, South Africa will be the BRICS presidency ', ' data ' = ' 2017-9-12 '),
Array (' title ' = ' = ' next year, South Africa will be the BRICS presidency ', ' data ' = ' 2017-9-12 '),
Array (' title ' = ' = ' next year, South Africa will be the BRICS presidency ', ' data ' = ' 2017-9-12 '),
Array (' title ' = ' = ' next year, South Africa will be the BRICS presidency ', ' data ' = ' 2017-9-12 '),
Array (' title ' = ' = ' next year, South Africa will be the BRICS presidency ', ' data ' = ' 2017-9-12 ')
);

echo Json_encode ($new);

?>

Effect:

Ajax instant Update get data combined with Ajax JS reference use of course need to build local environment and create PHP

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.