明白了。
```
//回调函数 getGPS
<script>
function getGPS(data) {
//do someting
}
</script>
<script src="请求地址巴拉巴拉&callback=回调函数">
</script>
```
没加 callback 服务器返回的是
```
{"status":"1","info":"OK","infocode":"10000","count":"1","geocodes":[{"formatted_address":"北京市朝阳区阜通东大街 6 号","country":"中国","province":"北京市","citycode":"010","city":"北京市","district":"朝阳区","township":[],"neighborhood":{"name":[],"type":[]},"building":{"name":[],"type":[]},"adcode":"110105","street":"阜通东大街","number":"6 号","location":"116.482086,39.990496","level":"门牌号"}]}
```
加了 callback 以后,服务器返回的是
```
getGPS({"status":"1","info":"OK","infocode":"10000","count":"1","geocodes":[{"formatted_address":"北京市朝阳区阜通东大街 6 号","country":"中国","province":"北京市","citycode":"010","city":"北京市","district":"朝阳区","township":[],"neighborhood":{"name":[],"type":[]},"building":{"name":[],"type":[]},"adcode":"110105","street":"阜通东大街","number":"6 号","location":"116.482086,39.990496","level":"门牌号"}]})
```
也就是说,服务器直接把 回调函数名+(返回数据) 给返回来了。 所以导致 getGPS(data)接收到的实参对象,所以执行 getGPS(data),此时 data 从形参变实参了,在再回调函数中 do something
问题是,用$.get 直接拿数据不香吗? API 这个回调函数的方式除了解决跨域 还有啥用处?