JSONP Client-specific implementations

Source: Internet
Author: User

JSONP Client-specific implementations
1. Remotely invoke a JS, the code is as follows:
<script type= "Text/javascript" >
var Localhandler = function (data) {
Alert (' I am a local function, can be called cross-domain remote.js file, remote JS brings the data is: ' + data.result);
};
</script>
<script type= "Text/javascript" src= "Http://remoteserver.com/remote.js" ></script>
The Remote.js file code is as follows:
Localhandler ({"Result": "I am the data brought by remote JS"});
2. Dynamically generated Scripts
<script type= "Text/javascript" >
callback function after getting the flight information query result
var Flighthandler = function (data) {
Alert (' Your flight results are: fare ' + Data.price + ' yuan, ' + ' + ' + data.tickets + ' Zhang. ‘);
};
Provide the URL address of the JSONP service (regardless of the type of address, the resulting return value is a piece of JavaScript code)
var url = "Http://flightQuery.com/jsonp/flightResult.aspx?code=CA1998&callback=flightHandler";
Create a script tag, set its properties
var script = document.createelement (' script ');
Script.setattribute (' src ', url);
Add the script tag to head, and the call starts
document.getElementsByTagName (' head ') [0].appendchild (script);
</script>
Flighthandler ({
"Code": "CA1998",
"Price": 1780,
"Tickets": 5
});
3. Encapsulating Code
Encapsulate the code to facilitate interaction with the user interface, enabling multiple and repeated calls.

JSONP Client-specific implementations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.