Files
freeCodeCamp/guide/chinese/miscellaneous/how-jsonp-is-different-from-json/index.md
2018-10-16 21:32:40 +05:30

22 lines
536 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: How Jsonp Is Different from JSON
localeTitle: Jsonp与JSON的区别
---
JSONP只是JSON包装在一个回调函数中。
JSONP对于发出跨域请求很有用出于安全原因这些请求通常被浏览器禁止。
```
// an example of JSON
{"weapon":"nunchucks","headband":"yellow"}
// an example of JSONP
myCallback({"weapon":"nunchucks","headband":"yellow"});
```
然后要访问存储在JSONP中的数据请定义回调函数
```
myCallback = function(data){
alert(data.weapon);
};
```