PHP Backstage Connect NetEase interface
Header ("Content-type:text/html;charset=utf-8");
Reading data from a file
$json _str =file_get_contents ("Wangyidata.json");
$str =file_get_contents ("http://c.m.163.com/nc/article/list/T1348647853363/0-20.html");
Echo $str;
Via Ajax to the foreground, package native JS
1.type request mode post, or get
2. Request URL Address
3. Parameters (Object)
4. Callback function
5. Synchronous or asynchronous
Request Way Request URL Address parameter: is an object callback function synchronous asynchronous
function Ajax (Type,url,par,fn,async) {
Determine if the request is legal
Because incoming may have uppercase or lowercase, unified conversion to uppercase, easy to verify
Type =type.touppercase ();
Judging legality
if (Type! = "GET" && type! = "POST") {
Console.error ("Illegal request Method");
Return
}
var ajaxobj;
Determine browser type, create Ajax object
if (window. XMLHttpRequest) {
Ajaxobj =new XMLHttpRequest ();
}else {
Ajaxobj =new ActiveXObject ("Microsoft.XMLHTTP");
}
Processing parameters
var data = "";
For (Var prop in par) {
Data + = prop + "=" +par[prop]+ "&";
}
Data =data.substr (0,DATA.LENGTH-1);
if (type = = "GET") {
URL + = "?" +data;
}
Call the Open
Ajaxobj.open (Type,url,async);
if (type = = "POST") {
Ajaxobj.setrequestheader ("Content-type", "application/x-www-form-urlencoded");
Ajaxobj.send (data);
}else{
Get
Ajaxobj.send ();
}
Listen for data return, notify user asynchronously via callback function
Ajaxobj.onreadystatechange =function () {
if (4 ==ajaxobj.readystate &&200 ==ajaxobj.status) {
FN (Ajaxobj.responsetext);
}
}
}
Foreground JS parsing JSON traversal JSON object array
var data = Json.parse (res);
for (var i in data) {
for (Var j in Data[i]) {
Data. I [j] ["XXXX"];
}
Another way to traverse
var data = Json.parse (res);
var Headarr = data["T1348647853363"];
For (var i= 2; i < headarr.length; i++) {
Console.log (headarr[i]["xxxx"]);
}
PHP passes an array of JSON objects passed through Ajax to the foreground, foreground parsing, and traversing JSON