首页 / AJAX / Jsonp实现跨域请求Ajax
Jsonp实现跨域请求Ajax
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Jsonp实现跨域请求Ajax,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2010字,纯文字阅读大概需要3分钟。
内容图文
![Jsonp实现跨域请求Ajax](/upload/InfoBanner/zyjiaocheng/1328/df63b91339ac42a88a4ba56e7517e2e4.jpg)
客户端
![技术分享](/upload/getfiles/default/2022/11/10/20221110054500570.jpg)
![技术分享](/upload/getfiles/default/2022/11/10/20221110054500596.jpg)
# !/usr/bin/env python import tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): def get(self, *args, **kwargs): self.render(‘index.html‘) def post(self, *args, **kwargs): self.render(‘index.html‘) settings ={ ‘template_path‘:‘views‘,#html文件模板路径配置‘static_path‘:‘statics‘,#css,js文件路径配置‘static_url_prefix‘:‘/sss/‘, } application = tornado.web.Application([ (r"/index", MainHandler), ],**settings) if__name__ == "__main__": application.listen(8000) tornado.ioloop.IOLoop.instance().start()
![技术分享](/upload/getfiles/default/2022/11/10/20221110054500570.jpg)
![技术分享](/upload/getfiles/default/2022/11/10/20221110054500596.jpg)
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <input type="button" value="Jsonp" onclick="DoJsonpAjax();"> <script src="{{static_url(‘jquery-3.1.1.js‘)}}"></script> <script> function xxoo(arg){ console.log(arg) } function DoJsonpAjax() { // var tag = document.createElement(‘script‘); // tag.src = "http://www.jxntv.cn/data/jmd-jxtv2.html?callback=list"; // document.head.appendChild(tag); // // document.head.removeChild(tag); //// $.ajax({ url: "http://tao.com:8001/index", dataType: ‘jsonp‘, jsonp:‘callback‘,//相当于在url: "http://tao.com:8001/index?callback= xxoo", jsonpCallback: "xxoo"//相当于在url: "http://tao.com:8001/index?callback= xxoo", }) } </script> </body> </html>
服务端
![技术分享](/upload/getfiles/default/2022/11/10/20221110054500570.jpg)
![技术分享](/upload/getfiles/default/2022/11/10/20221110054500596.jpg)
# !/usr/bin/env python import tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): def get(self, *args, **kwargs): callback = self.get_argument(‘callback‘) self.write("{}([11,22,33])".format(callback)) def post(self, *args, **kwargs): self.write(‘t2.post‘) settings ={ ‘template_path‘:‘views‘,#html文件模板路径配置‘static_path‘:‘statics‘,#css,js文件路径配置‘static_url_prefix‘:‘/sss/‘, } application = tornado.web.Application([ (r"/index", MainHandler), ],**settings) if__name__ == "__main__": application.listen(8001) tornado.ioloop.IOLoop.instance().start()
原文:http://www.cnblogs.com/shiluoliming/p/6567396.html
内容总结
以上是互联网集市为您收集整理的Jsonp实现跨域请求Ajax全部内容,希望文章能够帮你解决Jsonp实现跨域请求Ajax所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。