Welcome!

Open Source Cloud Authors: Elizabeth White, Yeshim Deniz, Charles Araujo, Liz McMillan, Pat Romanski

Related Topics: Machine Learning , Open Source Cloud, Release Management

Machine Learning : Blog Feed Post

What Is JSONP And Why Is It Useful?

JSON with Padding

By now most web developers are familiar with Ajax and the benefits that it provides.  In short, Ajax allows you to communicate asynchronously from the browser to a server.  This is usually done using the XMLHttpRequest object which is now supported in all major browsers.  Anyone who has used Ajax extensively is probably also aware of the cross-domain limitation placed on it.  The cross-domain limitation means that you can only communicate from the browser back to the domain from which the JavaScript was served.  Browser restrictions prevent you from using Ajax to communicate with an arbitrary web service in the cloud.  In the past this meant that if you wanted to communicate with an external server using Ajax, your requests had to be proxied through your own server-side code.

 

This is where JSONP comes in.  JSONP stands for JSON with Padding.  Don’t get too hung up on the name though.  In my opinion, the name will only confuse you.  I think it is a very poorly named technique as it really has nothing to do with what most people would think of as “padding”.  While Ajax communication is restricted to the server of origin, there is no such restriction on where you can load JavaScript source from using the standard <script> tag.  For example, it is now common to load JavaScript libraries from a CDN by pointing your <script> tag to the CDN URL for a given JavaScript library.  The fact that <script> tags can communicate with any server can be taken advantage of to achieve Ajax-like communication that avoids the cross-domain restriction.

 

Let’s imagine a scenario in which I have a web page that wants to read data from an external web service using an Ajax or Ajax-like mechanism.   Let’s say the web service is hosted on www.aserver.com.  The web service provides the data that I am interested in through a URL that looks like this:

http://www.aserver.com/some-data

So if I send a request to that URL I will receive back some data encoded in JSON.  If I try to use the normal XMLHttpRequest method to call this web service it will fail due to the cross-domain restriction.  This is where the <script> tag comes in.  Instead of using XMLHttpRequest, we will dynamically create a <script> tag to get the data.  A convenient property of the <script> tag is that it does not have to return JavaScript.  A <script> tag will load whatever is returned from the URL specified as its “src” attribute.

 

Let’s assume the web service will return JSON data that looks like this:
{['tim',john',mike']}

So if you created a <script> tag like this:

script = document.createElement(”script”);
script.type = “text/javascript”;
script.src = “http://www.aserver.com/some-data”;

 

You will end up with a <script> segment that looks like this after it loads the data:

<script>
{['tim',john',mike']}
</script>

 

Hmm, so now we have the data loaded into our page, but we have not done anything with it.  If we stopped here, you’d have to write more code to pull that data out of the <script> tag after it had loaded the data.  There is a better way.

 

Instead of specifying the <script> src attribute as:
http://www.aserver.com/some-data
Let’s append a parameter named callback to the URL, so we have this as the src attribute:
http://www.aserver.com/some-data?callback=my_callback

 

Now a web service that supports the JSON-P protocol can see this attribute and instead of just returning the data as before, it will wrap the data with a method call where the method named is specified by this callback parameter.  So now the data the web service returns will look like this:
my_callback({['tim',john',mike']})

 

Now after the data loads, you end up with a <script> segment that looks like this:
<script>
my_callback({['tim',john',mike']})
</script>

 

This is more useful because now immediatly after the data is loaded into the script it will make a call to a JavaScript method that I was able to specify in the callback parameter. This is very similar to the callbacks that you are able to provide to a traditional Ajax XMLHttpRequest method.

 

So now with JSONP you have a mechanism similar to the XMLHttpRequest method that allows you to request data from a remote server and it is not restricted to the origin domain.  If you are planning on using JSONP remember that the service that you want to communicate with also must understand the protocol and properly handle the callback wrapping of the data.

Read the original blog entry...

More Stories By Timothy Fisher

Timothy Fisher has recognized expertise in the areas of Java, Ruby, Rails, Social Media, Web 2.0, and Enterprise 2.o. He has served in technical leadership and senior architecture roles with companies such as Motorola, Cyclone Commerce, and Compuware. He is the author of the Java Phrasebook, and the Ruby on Rails Bible. Currently he is employed as a senior web architect with Compuware in Detroit, Michigan.

Follow Timothy on Twitter at http://twitter.com/tfisher

@ThingsExpo Stories
To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitoring and Cost Management … But How? Overwhelmingly, even as enterprises have adopted cloud computing and are expanding to multi-cloud computing, IT leaders remain concerned about how to monitor, manage and control costs across hybrid and multi-cloud deployments. It’s clear that traditional IT monitoring and management approaches, designed after all for on-premises data centers, are falling short in ...
Organizations planning enterprise data center consolidation and modernization projects are faced with a challenging, costly reality. Requirements to deploy modern, cloud-native applications simultaneously with traditional client/server applications are almost impossible to achieve with hardware-centric enterprise infrastructure. Compute and network infrastructure are fast moving down a software-defined path, but storage has been a laggard. Until now.
DXWorldEXPO LLC announced today that the upcoming DXWorldEXPO | CloudEXPO New York event will feature 10 companies from Poland to participate at the "Poland Digital Transformation Pavilion" on November 12-13, 2018.
Digital Transformation is much more than a buzzword. The radical shift to digital mechanisms for almost every process is evident across all industries and verticals. This is often especially true in financial services, where the legacy environment is many times unable to keep up with the rapidly shifting demands of the consumer. The constant pressure to provide complete, omnichannel delivery of customer-facing solutions to meet both regulatory and customer demands is putting enormous pressure on...
The best way to leverage your CloudEXPO | DXWorldEXPO presence as a sponsor and exhibitor is to plan your news announcements around our events. The press covering CloudEXPO | DXWorldEXPO will have access to these releases and will amplify your news announcements. More than two dozen Cloud companies either set deals at our shows or have announced their mergers and acquisitions at CloudEXPO. Product announcements during our show provide your company with the most reach through our targeted audienc...
In an era of historic innovation fueled by unprecedented access to data and technology, the low cost and risk of entering new markets has leveled the playing field for business. Today, any ambitious innovator can easily introduce a new application or product that can reinvent business models and transform the client experience. In their Day 2 Keynote at 19th Cloud Expo, Mercer Rowe, IBM Vice President of Strategic Alliances, and Raejeanne Skillern, Intel Vice President of Data Center Group and ...
More and more brands have jumped on the IoT bandwagon. We have an excess of wearables – activity trackers, smartwatches, smart glasses and sneakers, and more that track seemingly endless datapoints. However, most consumers have no idea what “IoT” means. Creating more wearables that track data shouldn't be the aim of brands; delivering meaningful, tangible relevance to their users should be. We're in a period in which the IoT pendulum is still swinging. Initially, it swung toward "smart for smart...
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22nd international CloudEXPO | first international DXWorldEXPO and will feature technical sessions from a rock star conference faculty and the leading industry players in the world.
DXWorldEXPO LLC announced today that All in Mobile, a mobile app development company from Poland, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. All In Mobile is a mobile app development company from Poland. Since 2014, they maintain passion for developing mobile applications for enterprises and startups worldwide.
In his keynote at 19th Cloud Expo, Sheng Liang, co-founder and CEO of Rancher Labs, discussed the technological advances and new business opportunities created by the rapid adoption of containers. With the success of Amazon Web Services (AWS) and various open source technologies used to build private clouds, cloud computing has become an essential component of IT strategy. However, users continue to face challenges in implementing clouds, as older technologies evolve and newer ones like Docker c...
DXWorldEXPO LLC announced today that ICC-USA, a computer systems integrator and server manufacturing company focused on developing products and product appliances, will exhibit at the 22nd International CloudEXPO | DXWorldEXPO. DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. ICC is a computer systems integrator and server manufacturing company focused on developing products and product appliances to meet a wide range of ...
Coca-Cola’s Google powered digital signage system lays the groundwork for a more valuable connection between Coke and its customers. Digital signs pair software with high-resolution displays so that a message can be changed instantly based on what the operator wants to communicate or sell. In their Day 3 Keynote at 21st Cloud Expo, Greg Chambers, Global Group Director, Digital Innovation, Coca-Cola, and Vidya Nagarajan, a Senior Product Manager at Google, discussed how from store operations and ...
We are seeing a major migration of enterprises applications to the cloud. As cloud and business use of real time applications accelerate, legacy networks are no longer able to architecturally support cloud adoption and deliver the performance and security required by highly distributed enterprises. These outdated solutions have become more costly and complicated to implement, install, manage, and maintain.SD-WAN offers unlimited capabilities for accessing the benefits of the cloud and Internet. ...
Headquartered in Plainsboro, NJ, Synametrics Technologies has provided IT professionals and computer systems developers since 1997. Based on the success of their initial product offerings (WinSQL and DeltaCopy), the company continues to create and hone innovative products that help its customers get more from their computer applications, databases and infrastructure. To date, over one million users around the world have chosen Synametrics solutions to help power their accelerated business or per...
Dion Hinchcliffe is an internationally recognized digital expert, bestselling book author, frequent keynote speaker, analyst, futurist, and transformation expert based in Washington, DC. He is currently Chief Strategy Officer at the industry-leading digital strategy and online community solutions firm, 7Summits.
Founded in 2000, Chetu Inc. is a global provider of customized software development solutions and IT staff augmentation services for software technology providers. By providing clients with unparalleled niche technology expertise and industry experience, Chetu has become the premiere long-term, back-end software development partner for start-ups, SMBs, and Fortune 500 companies. Chetu is headquartered in Plantation, Florida, with thirteen offices throughout the U.S. and abroad.
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science," is responsible for setting the strategy and defining the Big Data service offerings and capabilities for EMC Global Services Big Data Practice. As the CTO for the Big Data Practice, he is responsible for working with organizations to help them identify where and how to start their big data journeys. He's written several white papers, is an avid blogge...
Charles Araujo is an industry analyst, internationally recognized authority on the Digital Enterprise and author of The Quantum Age of IT: Why Everything You Know About IT is About to Change. As Principal Analyst with Intellyx, he writes, speaks and advises organizations on how to navigate through this time of disruption. He is also the founder of The Institute for Digital Transformation and a sought after keynote speaker. He has been a regular contributor to both InformationWeek and CIO Insight...
"IBM is really all in on blockchain. We take a look at sort of the history of blockchain ledger technologies. It started out with bitcoin, Ethereum, and IBM evaluated these particular blockchain technologies and found they were anonymous and permissionless and that many companies were looking for permissioned blockchain," stated René Bostic, Technical VP of the IBM Cloud Unit in North America, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Conventi...