Examples of cross-domain jsonp

First, what is the cross-domain

Second, how to solve cross-domain

1. The common front end JSONP

2. Configuration server parsing the HTTP protocol header

Third, the implementation examples JSONP

<! DOCTYPE HTML > 
< HTML > 
< head > 
    < title > JSONP cross-domain Test </ title > 
</ head > 
< body > 
    < Script type = "text / JavaScript" > 
        function RES (R & lt) {// definition of callback receiving a return result 
            the console.log (R & lt) 
        } 
    </ Script > 
    < Script the src = "./ api.json? callback RES =" > 
//? path before the request
     //? callback may be abbreviated after cb, is the name of the callback function
</
script> </body> </html>

Json file content request is as follows:

res({"data":"js"})

Go to the browser to open the html file, open the console, the effect is as follows:

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/zhuxingqing/p/11220680.html