谁能用外行的术语解释 JSONP 是什么? [英] Can anyone explain what JSONP is, in layman terms?

查看:23
本文介绍了谁能用外行的术语解释 JSONP 是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 JSONP 是带有填充的 JSON.

I know JSONP is JSON with padding.

我了解什么是 JSON,以及如何通过 jQuery.getJSON().但是,我不明白介绍JSONP时callback的概念.

I understand what JSON is, and how to use it with jQuery.getJSON(). However, I do not understand the concept of the callback when introducing JSONP.

谁能向我解释一下这是如何工作的?

Can anyone explain to me how this works?

推荐答案

前言:

这个答案已经有六年多了.虽然JSONP的概念和应用没有改变(即答案的详细信息仍然有效),您应该尽可能使用 CORS(即您的服务器API 支持它,并且浏览器支持就足够了),因为 JSONP 具有固有的安全风险.

Preface:

This answer is over six years old. While the concepts and application of JSONP haven't changed (i.e. the details of the answer are still valid), you should look to use CORS where possible (i.e. your server or API supports it, and the browser support is adequate), as JSONP has inherent security risks.

JSONP(JSON with Padding)是一种常用的方法绕过 Web 浏览器中的跨域策略.(您不得向浏览器认为位于不同服务器上的网页发出 AJAX 请求.)

JSONP (JSON with Padding) is a method commonly used to bypass the cross-domain policies in web browsers. (You are not allowed to make AJAX requests to a web page perceived to be on a different server by the browser.)

JSON 和 JSONP 在客户端和服务器上的行为不同.JSONP 请求不会使用 XMLHTTPRequest 和相关的浏览器方法进行分派.而是创建一个

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆