废话少数,直接上代码!!!!!!!!!!
html:
<!DOCTYPEhtml> <htmllang="en"> <head> <Metacharset="UTF-8"> <title>Document</title> <scriptsrc="http://cdn.bootcss.com/jquery/3.1.1/jquery.js"></script> </head> <body> <ulid="list"></ul> <script> varurl="http://japi.juhe.cn/tv/getCategory?key=1e90c38759b2271714f60133b04f75c4" varstr=""; $.ajax({ type:"get",contentType:"application/json;charset=utf-8;",dataType:"json",url:"ajax.PHP",success:function(data){ varlen=data.result.length; //console.log(data.result.name) for(vari=0;i<len;i++){ varli="<lidata-id="+data.result[i].id+">"+data.result[i].name+"</li>"; //console.log(`${data.result.name}123`) //varli=`<lidata-id=${data.result[i].id}>${data.result[i].name}</li>` str+=li; } $("#list").html(str); } }) </script> </body> </html>
<?PHP //cors跨域 //设置请求头部信息啊 header("Access-Control-Allow-Origin:*"); //设置跨域方式 header("Access-Control-Allow-Method:GET"); //读取数据的地址 $URL="http://japi.juhe.cn/tv/getCategory?key=1e90c38759b2271714f60133b04f75c4"; //读取数据 $html=file_get_contents($URL); echo$html; ?>原文链接:https://www.f2er.com/ajax/161195.html