【笔记】JSONP跨域访问
前言
JSONP跨域访问
原理的实践
- 创建一个
hello.json
文件,文件内容编写js格式的函数,对象作为函数的参数
1 | hello({"name":"zhangsan"}) |
- 先定义回调函数
1 | function hello(data) { |
- 通过script标签的src属性引入json文件
1 | <script src="hello.json"></script> |
通过jQuery实现进阶
1 | $.ajax({ |
JSONP跨域访问
hello.json
文件,文件内容编写js格式的函数,对象作为函数的参数1 | hello({"name":"zhangsan"}) |
1 | function hello(data) { |
1 | <script src="hello.json"></script> |
1 | $.ajax({ |