python&JSONP(Jquery篇),,采用Jquery发送


采用Jquery发送跨域请求:

 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4     <meta charset="UTF-8"> 5     <title>Title</title> 6 </head> 7 <body> 8     <h1>后台获取结果</h1> 9     {{ result }}10     <h1>JS直接获取结果</h1>11     <input type="button" value="XHR数据" onclick="xhrContent();">12     <input type="button" value="JSONP数据" onclick="getContent();">13     <input type="button" value="Jquery数据" onclick="JqueryContent();">14     <div id="container"></div>15     <script src="/static/jquery.min.js"></script>16     <script>17         function JqueryContent(){18             $.ajax({19                 url:"http://www.jxntv.cn/data/jmd-jxtv2.html?_=14543768704003",20                 type:"POST",21                 dataType:"jsonp", // 请求格式22                 jsonp:"callback",  // 参数名23                 jsonpCallback:"list" // 默认回调函数24             })25         }26         function list(arg){27             console.log(arg)28         }29         function xhrContent(){30             var xhr = new XMLHttpRequest();31             xhr.open(‘GET‘,‘http://www.jxntv.cn/data/jmd-jxtv2.html?callback=list&_=14543768704003‘);32             xhr.onreadystatechange = function(){33                 console.log(xhr.responseText);34             }35             xhr.send();36         }37         function getContent(){38             var tag = document.createElement(‘script‘);39             tag.src= ‘http://www.jxntv.cn/data/jmd-jxtv2.html?callback=list&_=14543768704003‘;40             document.head.appendChild(tag); // 表示创建一个标签,并且放到head中41             document.head.removeChild(tag);42         }43         function list(arg){44             console.log(arg);45         }46     </script>47 </body>48 </html>

python&JSONP(Jquery篇)

评论关闭