ajax, json, jsonp, restful的区别
2013-09-03 09:44
465 查看
Ajax, or more properly, AJAX, stands for Asynchronous Javascript And Xml. Technically it refers to any asynchronous request made by the browser (anything that uses anXmlHttpRequest) on behalf of some script running on the current page, regardless of what content-type is returned. It can also be used to describe a certain pattern of constructing a page/site where most/all of the content is fetched/updated dynamically on the page. When used to describe a data format, "ajax" typically means "xml". JSON is a data encoding format. The name itself is an acronym for "JavaScript Object Notation". JSON-formatted data looks like: {"key": "value1", "key2": {"number": 1, "array": [0, 1, 2]}} JSON data may be fetched by an AJAX request, though it is quite commonly used in other contexts as a lightweight, extensible, and easy-to-parse data exchange format. JSONP is simply JSON-formatted data wrapped in a callback function. The "P" stands for "with Padding", which is kind of stupid unless you like to think of function calls as "padding". In any case, JSONP data will look like: someFunction({"key": "value1", "key2": {"number": 1, "array": [0, 1, 2]}}); As such, JSONP is really just a JavaScript snippet, and unlike JSON is not used outside of the context of JavaScript, browsers (or other JavaScript-capable clients), and AJAX requests. The reason for using JSONP is that it allows the same-origin policy to be subverted. A script that was sourced in from site X cannot make a direct request to site Y if site Y is on a different domain from site X. But if site Y's server can send JSONP-formatted responses, then the script from site X can add a new <script>tag to the document that references a URL on site Y, and when the response from site Y is loaded it will invoke some callback function that script X has defined in the document, thus giving script X access to data that was loaded dynamically from site Y. Note that JSONP data is not (typically) requested using an XmlHttpRequest. It can be done this way, subject to the standard caveats of the same-origin policy, but then you lose the cross-domain magic that makes JSONP useful in the first place. REST is simply the formal spec/description of how HTTP actually works/is intended to be used. If you understand the concept of a URL being used to request a corresponding resource from a server and the difference between Getand Postthen you really know all you need to about REST. ///未完待续.......... |
相关文章推荐
- 浅析json与jsonp区别及通过ajax获得json数据后格式的转换
- 浅谈JSON和JSONP区别及jQuery的ajax jsonp的使用
- json和jsonp和ajax的实质和区别
- JS与JSON、JSON与JSONP、JSONP与AJAX的区别
- 前端跨域问题,以及ajax,jsonp,json的区别
- Jsonp 关键字详解及json和jsonp的区别,ajax和jsonp的区别
- Jsonp 关键字详解及json和jsonp的区别,ajax和jsonp的区别
- Jsonp 关键字详解及json和jsonp的区别,ajax和jsonp的区别
- 浅谈JSON和JSONP区别及jQuery的ajax jsonp的使用
- 浅谈JSON和JSONP区别及jQuery的ajax jsonp的使用
- json和jsonP的区别和联系以及ajax和jsonP的区别
- $.ajax解决跨域问题 关于json与jsonp格式的区别
- json与jsonp实质性区别,顺便AJAX
- JSON、JSONP、Ajax的区别
- 浅析json与jsonp区别及通过ajax获得json数据后格式的转换
- Json和JsonP及ajax跨域的解决办法
- node.js与ajax交互之 json 与 jsonp 数据格式问题
- input屏蔽历史记录 ;function($,undefined) 前面的分号是什么用处 JSON 和 JSONP 两兄弟 document.body.scrollTop与document.documentElement.scrollTop兼容 URL中的# 网站性能优化 前端必知的ajax 简单理解同步与异步 那些年,我们被耍过的bug——has
- ajax,json,跨域jsonp总结
- ajax异步 servlet返回json格式数据注意 “ ‘ 的区别