JSONP Tutorial

JSONP Tutorial

In this chapter we will introduce you to the knowledge of JSONP.

Jsonp (JSON with Padding) is a "usage mode" of json, which allows web pages to obtain data from other domain names (websites), that is, read data across domains.

Why do we need a special technology (JSONP) to access data from different domains (websites)? This is because of the same origin policy.

The same-origin policy is a well-known security policy proposed by Netscape. All browsers that support JavaScript now use this policy.

JSONP Application

1. Server-side JSONP format data

If the customer wants to access: //m.sbmmt.com/try/ajax/jsonp.php? jsonp=callbackFunction.

Suppose the customer expects to return JSON data: ["customername1", "customername2"].

The data actually returned to the client is displayed as: callbackFunction(["customername1","customername2"]).

The server-side file jsonp.php code is:

2. The client implements the callbackFunction function

Page display


Complete code of client page

   JSONP 实例 

jQuery using JSONP

The above code can use jQuery code example:

   JSONP 实例  


Continuing Learning
||
JSONP 实例
submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!