Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONP是什么 #33

Closed
zhouzhongyuan opened this issue Mar 25, 2017 · 1 comment
Closed

JSONP是什么 #33

zhouzhongyuan opened this issue Mar 25, 2017 · 1 comment

Comments

@zhouzhongyuan
Copy link
Owner

zhouzhongyuan commented Mar 25, 2017

  • JSONP: JSON with Padding 带填充的JSON
  • JSONP is a method commonly used to bypass the cross-domain policies in web browsers.
  • 为什么会有JSONP?

    you are not allowed to make AJAX requests to a webpage perceived to be on a different server by the browser.
    其实,上述解释不严谨。Firefox2.0之前是允许跨域的。(这句话是周中原说的)

  • 一个简单的实现
@zhouzhongyuan
Copy link
Owner Author

实现的时候

  • script的url最后的函数名一定不能固定。固定之后,jsonp返回之后,可能找不到对应的回调函数。
  • 为了产生一个唯一的回调函数名,使用了count++。使用uuid应该也是可以的,但是json本来就是一个很小的函数,去用uuid有点杀鸡用牛刀。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant