Archive by Author

JSONP First Timer

You already know ajax is one-man’s-girl, no way to make it work cross-domain(not even subdomain) due to browsers’ same origin policy security restriction. But using ajax is so sleek, you can’t even resist yourself using it under different domains. There is always a way around for everything. Do I sound contradictory? Ajax is based on the XMLHttpRequest and as long as we use it we can’t do cross-domain data transfer. Let’s think something else other than ajax.

We are used to loading images, css, javascript files from other domains and it’s okay if we use any server-side dynamic link as the src, this is a common phenomena on web. For example:

<script type="text/javascript" src="http://www.other-domain.com/dynamic-js.php?id=5&name=Matt"></script>

There is no security restriction including javascript source from different domains, and fortunately enough you can pass GET variables (don’t over-expect for POST) with the url. This is how JSONP (JSON with padding) works, thanks to the open policy for <script> tag. May be you’r already thinking how to implement this idea, hold on! you don’t need to reinvent the wheel.

Here comes jQuery’s $.getJSON(), with this function you can pass url of another domain and get JSON data. Lemme warn you, for the very first time most of you won’t be able to make it work. Here is an example:

$.getJSON("http://www.other-domain.com/dynamic-js.php?id=5&name=Matt&jsoncallback=?",
function(data){
    // your code goes here
});

You need to understand this “jsoncallback=?” bit clearly. From your firebug Net panel you can see the “?” is replaced with “jsonp1277557614558″ (random value on each request).

JSONP Net Panel screen shot

The common mistake you’re gonna do is you expect to see something on firebug’s Console tab, but nothing there, once again JSONP is NOT Ajax request. This is merely an external javascript file being added to your document dynamically, if you don’t believe me on your firebug panel click the JS from Net tab to filter out the JS only(marked in the screen-shot above). You’ll definitely see the JSONP url there. This is the client-side part of $.getJSON(). The confusion still remains with the server-side code.

Back to “http://www.other-domain.com/dynamic-js.php?id=5&name=Matt&jsoncallback=?”, the file being called is dynamic-js.php. Put this one line of code in that file:

<?php print_r($_GET); ?>

And check the Response output from firebug’s Net tab. It’ll be something like:

Array
(
    [id] => 5
    [name] => Matt
    [jsoncallback] => jsonp1277557614558
)

In Ajax when the dataType is json the response from server-side script is just the json string:

{
	// your json data
}

Here is the most important part, unlike ajax for JSONP the $.getJSON() expects the response like:

 jsonp1277557614558({
	// your json data here
})

So you must wrap the json output with jsonp1277557614558( ). If you don’t do it the callback will fail silently without any error, which makes it tough to detect the exact problem. Remember the jsonp1277557614558 is a random string. For php the code will be something like this:

<?php
// your code here
// get the output in an array say $output_array
$jc = $_GET['jsoncallback'];
echo $jc . '(' . json_encode($output_array) . ')';
/*
// For ajax response, simply
echo json_encode($output_array);
// is enough
*/
?>

This is the most crucial thing, most programmers do the mistake for their very first time as there is no clear elaboration on $.getJSON documentation page. FYI, json_encode() function is not available on older version of php. You can get the php class from json.org.

Hope your $.getJSON() is now working! :)

Comments, criticism are most welcome.

Windows Phone 7 Applications have to be allowed by Microsoft

While virtually all mobile platforms now have app stores, Microsoft is taking a few cues from Apple. For instance, the software Giant said all windows Phone 7 applications in the Windows Marketplace for Mobile store must be approved by Microsoft first, as Apple requires for its App Store.

Microsoft has announced more details about Windows Phone 7 Series applications in its online store as it moves to get third-party developers excited about the new platform, but Microsoft didn’t specify which apps will be offered for the successor to the current Windows Mobile operating system, or the price ranges. But the company said its Silverlight multimedia technology will be the basis for “rich Internet application” development. Microsoft also said Windows Phone 7 supports XNA programming tools for game development.

The Windows Phone 7 Series platform was unveiled in mid-February at the World Mobile Congress.

Windows phone 7 cannot run applications written for older versions

Microsoft Corp. has said its new software for smart phones, Windows Phone 7 series, is a “clean break” with the past. But Windows phone 7 cannot run any applications written for older versions of Microsoft’s phone software. Windows Phone 7 Series is designed for touch screens that work well with fingers but don’t work with fine styluses.

The news also leaves software developers with a dilemma: they can write applications for Windows Mobile 6.5, which will soon be a dead end, or they can write for Windows Phone 7, which isn’t coming out until later this year.

Phone providers compete in part by providing support for as many applications as they can, and everyone is trying to catch up the success to Apple Inc.’s App Store. Among tens of thousands of applications written for different versions of Windows, few of those applications are up to today’s standards.

Palm Inc. made a similar “clean break” last year, abandoning an operating system that was more than a decade old in favor of a completely new one. However, the new system is able to run applications written for the old one.

Silver jubilee of Dot-com

Exactly 25 years ago, computer manufacturer Symbolics, Inc. registered the first .com web domain ever: symbolics.com. In 1985, a Cambridge, Mass, company named Symbolics became the first to register a dot-com domain. By the end of the year, only five other companies had dot-com addresses, and it was nearly two years before there were a hundred.

And while the .com crash proved that a well-chosen name isn’t enough for a successful company, .coms still play a very important part of our online lives. Despite many other top-level domains available, .com is still the most coveted TLD — the one that many people still associate with the world wide web in general.

In 1997, when the Internet was start booming there were about one million dot-coms had been registered. When the first dot-com addresses were registered, no one expected it would become as pervasive in our lives as it is today. Today, there are about 80 million dot-com sites.

Samsung’s upcoming Slate PC will compete with iPad

According to Samsung, iPad is lack of processing power and it doesn’t have enough connectivity options. Samsung claimed this tablet PC has more potential than an iPad. It also claimed that Slate PC will also have greater flexibility. Samsung reports that it is looking at two platforms from Intel to power the unnamed device: Atom or the Moorestown System on a Chip.


Samsung’s Emmanuele Silanesu assures that the upcoming new tablet pc will have a much stronger focus on the consumer market than the Q1. So that consumer can get an attractive device in a reasonable price.

Opera has decided to promote Opera Mini 5 and Opera Mobile 10 to stable versions

Popular mobile internet browser provider Opera has decided to remove beta tag from its latest mobile browsers Opera mini 5 and Opera mobile 10. The beta version of Opera Mini 5 and Opera mobile 10 have been used for several months. From now the two popular mobile web browsers like Opera Mini 5 and Opera mobile 10 are available in stable version.

Opera mini 5 beta has brought many expansions including tabs options, and speed dial option. Opera Mobile 10 beta also have some improvements like tabs and speed dial (probably being the most important). This expansions have made its (Opera mini 5 and Opera mobile 10) predecessor pale in comparison.

Compared to the betas, Opera Mini 5 and Opera Mobile 10 don’t bring any new feature.

MOG Mobile Music Service for $10/month

MOG announced the launch impending mobile application for iPhone and Android mobile in the early second quarter of this year. It will require a fee cost $10 per month including on-demand desktop streaming. This fee is $5 lower than undercuts competitor Rhapsody’s Rhapsody $15/month fee.

Back in December, the MP3 blog network launched its all-you-can-eat music-streaming service, offering on-demand listening to its seven million song library from a web browser for $5 per month.

The mobile version of the All Access service includes the ability to download tracks to a local cache on listening device. An “HQ Audio” option allows users to opt for a higher audio quality download in exchange for the tradeoff of larger file sizes.

MOG has just raised $9.5 million funding for tune. This funding is backed by Universal Music Group and Sony Music.

Intel releases new server chips ahead of rival AMD

Recently Intel Corp. has released its newest server chips ahead of its rival AMD (Advanced Micro Devices Inc.). The chips will be released under the Xeon product line for servers, and Core i7 for desktop computers. About one-third of the market is running on chips made more than four years ago. Intel’s new chips are the first of Intel’s server chips featuring smaller transistors that have helped the company’s laptop and desktop chips push stronger performance while eking out better energy efficiency.

The new microprocessors, designed to power both servers and high-end desktop PCs. Intel says these can encode and decipher files much more rapidly, and effectively.
AMD also announced to the release new chips within few weeks. It says AMD’s upcoming new chips will also offer increases in speed pushed by a dramatic redesign.

It remains to be seen how AMD will match up against Intel’s latest chips.

Google unveils AT&T-compatible Nexus One

Google’s Nexus One smartphone was unveiled in January for use only on the T-Mobile network. Recently Google announced a Nexus One compatible with AT&T’s 3G network.

Unlike the T-Mobile version of the Nexus One, the AT&T-compatible model isn’t available at a subsidy from the carrier. Customers have to buy the unlocked AT&T-compatible version of the phone.

The AT&T version of the Nexus One is also compatible with the Rogers network in Canada, the same provider that sells the iPhone and, for the first time, Google will ship the device to Canada.

While both T-Mobile and AT&T use GSM-based cell phone standards, the two networks use different frequency bands for their respective 3G traffic. Hence, the T-Mobile-compatible unlocked Nexus One could be used on AT&T, but only at EDGE speeds. Both the T-Mobile and AT&T versions of the Nexus One can be used internationally in most countries.

Google Nexus One sales lag Apple, Motorola: Flurry

Nexus One phone is first hardware device directly to consumers by Google. The initial sales of this smartphone are ahead of Apple’s iPhone and Motorola’s Droid. An analytics firm named Flurry has reported this news recently. According to a report by Flurry, Google sold roughly 135,000 of its new Nexus One phones in its first 74 days on the market. By contrast, during the same timeframe Apple sold 1 million of the original iPhones in the first 74 days, while Motorola sold 1.05 million Droid phones based on Google’s Android software.

According to a recent report by comScore, the market share of Android-based smartphones in the U.S. grew to 7.1 percent in January from 2.8 percent in October 2009. By contrast, Apple’s share grew at a much slower pace, reaching 25.1 percent in January compared with 24.8 percent in October.

Though The users of Nexus One smartphone think this phone is overpriced.