Cross-domain communications with JSONP using JavaScript and jQuery!

Asynchronous JavaScript and XML (Ajax) is the key technology driving the new generation of Web sites, popularly termed as Web 2.0 sites.Ajax allows for data retrieval in the background without interfering with the display and behavior of the Web application. Data is retrieved using the XMLHttpRequest function, which is an API that lets client-side JavaScript make HTTP connections to remote servers.

This approach, however, does not allow cross-domain communication because of restrictions imposed by the browser. If you try to request data from a different domain, you will get a security error.

The same-origin policy limitations:

The same-origin policy prevents a script loaded from one domain from getting or manipulating properties of a document from another domain. That is, the domain of the requested URL must be the same as the domain of the current Web page.

How to resolve?

Technique 1:

One relatively simple way to overcome this limitation is to have the Web page request data from the Web server it originates from, and to have the Web server behave as a proxy relaying the request to the actual third-party servers. Although widely used, this technique isn’t scalable.

Technique 2:

Another way is to use frame elements to create new areas in the current Web page, and to fetch any third-party content using GET requests. After being fetched, however, the content in the frames would be subject to the same-origin policy limitations.

Technique 3 (Using JSONP):

A more promising way to overcome this limitation is to insert a dynamic script element in the Web page, one whose source is pointing to the service URL in the other domain and gets the data in the script itself. When the script loads, it executes.
It works because the same-origin policy doesn’t prevent dynamic script insertions and treats the scripts as if they were loaded from the domain that provided the Web page. But if this script tries to load a document from yet another domain, it will fail. Fortunately, you can improve this technique by adding JavaScript Object Notation (JSON) to the mix.

JSONP Using Javasript:

Your client-side code:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
<title>jsonp</title>
</head>
<body>
<span></span>
<script>
//this function is the callback, it needs to be a global variable
function readResponse(response){
document.getElementsByTagName('SPAN')[0].innerHTML = response.time + ' is from  php file';
console.log(response);
}
(function(){
//note the "readResponse" at the end
var src = 'http://www.your-cross-domain.com/index.php?id=18&callback=readResponse',
script = document.createElement('SCRIPT');
script.src = src;
document.body.appendChild(script);
})();

</script>
</body>
</html>

Your server-side coding:

<?php
$array = array("time"=>time());
if($_GET['callback']){
header('Content-type: application/json');
echo $_GET['callback']."(".json_encode($array).")";
exit();
}
?>

JSONP using jQuery:

<!DOCTYPE html> <html> <head>   <style>img{ height: 100px; float: left; }</style>   <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body>   <div id="images"> </div> <script> $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",   {     tags: "cat",     tagmode: "any",     format: "json"   },   function(data) {     $.each(data.items, function(i,item){       $("<img/>").attr("src", item.media.m).appendTo("#images");       if ( i == 3 ) return false;     });   });</script> </body> </html>

SEO: Is it all you need?

SEO is a dominating concern among store owners.  So much so that for many site operators it is almost the ONLY thing they focus on. In her article SEO – Is It All You Need? Michelle Symonds challenges this flawed assumption, and offers a number of other  issues which should be considered or addressed by [...]Copyright © 2010 StrikeHawk eCommerce, Inc. All rights reserved. acf0a32453123d28e5de0c448915c1de (77.92.90.2) <a href="http://www.oscommerceuniversity.com/blog/?p=233#comments” title=”to the comments”>To the comments, Author: <a href="http://www.oscommerceuniversity.com”>David M. Graham

Cross-domain communications with JSONP using JavaScript and jQuery!

Asynchronous JavaScript and XML (Ajax) is the key technology driving the new generation of Web sites, popularly termed as Web 2.0 sites.Ajax allows for data retrieval in the background without interfering with the display and behavior of the Web application. Data is retrieved using the XMLHttpRequest function, which is an API that lets client-side JavaScript make HTTP connections to remote servers.

This approach, however, does not allow cross-domain communication because of restrictions imposed by the browser. If you try to request data from a different domain, you will get a security error.

The same-origin policy limitations:

The same-origin policy prevents a script loaded from one domain from getting or manipulating properties of a document from another domain. That is, the domain of the requested URL must be the same as the domain of the current Web page.

How to resolve?

Technique 1:

One relatively simple way to overcome this limitation is to have the Web page request data from the Web server it originates from, and to have the Web server behave as a proxy relaying the request to the actual third-party servers. Although widely used, this technique isn’t scalable.

Technique 2:

Another way is to use frame elements to create new areas in the current Web page, and to fetch any third-party content using GET requests. After being fetched, however, the content in the frames would be subject to the same-origin policy limitations.

Technique 3 (Using JSONP):

A more promising way to overcome this limitation is to insert a dynamic script element in the Web page, one whose source is pointing to the service URL in the other domain and gets the data in the script itself. When the script loads, it executes.
It works because the same-origin policy doesn’t prevent dynamic script insertions and treats the scripts as if they were loaded from the domain that provided the Web page. But if this script tries to load a document from yet another domain, it will fail. Fortunately, you can improve this technique by adding JavaScript Object Notation (JSON) to the mix.

JSONP Using Javasript:

Your client-side code:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
   "http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">
<head>
    <title>jsonp</title>
</head>
<body>
    <span></span>
    <script>
        //this function is the callback, it needs to be a global variable
        function readResponse(response){
            document.getElementsByTagName('SPAN')[0].innerHTML = response.time + ' is from  php file';
            console.log(response);
        }
        (function(){
            //note the "readResponse" at the end
            var src = 'http://www.your-cross-domain.com/index.php?id=18&callback=readResponse',
                script = document.createElement('SCRIPT');
            script.src = src;
            document.body.appendChild(script);
        })();

    </script>
</body>
</html></code>

Your server-side coding:

<?php
$array = array("time"=>time());
if($_GET['callback']){
    header('Content-type: application/json');
    echo $_GET['callback']."(".json_encode($array).")";
    exit();
}
?>

 JSONP using jQuery:

<!DOCTYPE html> <html> <head>   <style>img{ height: 100px; float: left; }</style>   <script src="http://code.jquery.com/jquery-latest.js"></script> </head> <body>   <div id="images"> </div> <script> $.getJSON("http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?",   {     tags: "cat",     tagmode: "any",     format: "json"   },   function(data) {     $.each(data.items, function(i,item){       $("<img/>").attr("src", item.media.m).appendTo("#images");       if ( i == 3 ) return false;     });   });</script> </body> </html>

Obis proudly launches its new official website

Thanks to great efforts of all the employees – from designers, developers to marketers working with their minds and hearts, we proudly present our new corporate website for 2011.

Great efforts from designers, developers and marketing team have made ideas become our new corporate website

“Simplicity is the best” is the main concept of our artwork. The website features the most relevant information about Obis, from About us to Services, from Clients to Careers. Everything is presented in  the least detailed presentation with real pictures of our company’s employees. Feel free to discover our world right here at: www.obisgroup.com.

For a brief introduction, Obis is a leading company in Ecommerce solutions, helping businesses boost their online profit.  We offer simple yet effective solutions, from designing your e-store to creating online strategies and operation management. With a variety of large customers from North America and Europe, OBIS has proved its expertise in guiding companies to take advantage of the revenue opportunities in online market places.

Obis is proud to present our new online shop ‘www.nongsanngon.com.vn’

“Visit www.nongsanngon.com.vn and let us make your daily shopping as easy as ABC. It’s the great way to save your time and money”.

www.nongsanngon.com.vn is a B2C channel which brings a wide range of regional agricultural products. Young women who are always busy working are our target customers. With many years working in the e-commerce field, we are very confident that we provide our customers the most convenient way for online shopping while maintaining a high security for payment.

Moreover, the online super-market will gather a big among suppliers, giving them the platform to showcase and sell their products as well as helping them to increase their brand identity through an effective online marketing channel.

Obis proudly launches its new officially website

Thanks to great efforts of all the employees – from designers, developers to marketers working with all their minds and hearts, we proudly present our new corporate website for 2011.

“Simplicity is the best” is the main concept of our artwork. There’s no need to say anything else, feel what you see from us: www.obisgroup.com.

Starting from Spain, OBIS GROUP is one of the leading companies in Ecommerce solutions, helping business boost their online profit. We offer simple yet effective solutions, from designing your e-store to creating online strategies and operation management. With a variety of large customers from North America and Europe, OBIS GROUP has proved its expertise in guiding companies to take advantage of the revenue opportunities in online market place.

Nong San Ngon

OBIS is proudly to present our new internet portal ‘www.nongsanngon.com.vn’. The online super market was launched to showcase/sell manufacturers’ agriculture goods without the involvement of any middleman. This innovative online super market is a as well an opportunity to promote the varieties and important of agriculture goods in everyday life.

The idea was to create a platform, which not only acted as an online shop but also as a business tool, aiming to educate Vietnamese farmer, familiarizing them with the new e-commerce technology. After being educated and trained by our team, manufactures all over the region can use nongsanngon website as a channel to promote, distribute and sell their own goods over the internet to end-users.

Warning: require_once(./includes/database.inc) [function.require-once]: failed to open stream: No such file or directory in /public_html/includes/bootstrap.inc on line 1021

All of sudden I got following error in one of my Drupal website

Warning: require_once(./includes/database.inc) [function.require-once]: failed to open stream: No such file or directory in /public_html/includes/bootstrap.inc on line 1021

Fatal error: require_once() [function.require]: Failed opening required ‘./includes/database.inc’ (include_path=’.:/usr/lib/php:/usr/local/lib/php’) in /public_html/includes/bootstrap.inc on line 1021

Digging down further I discovered that the files are somehow corrupted as I had moved the files from one host to another. I uploaded files again and it solved the problem.

Also a lot of folders were not uploaded correctly.

Re-uploading all the files solved the problem.

How to schedule a WordPress blog post for the future

In case you wish to publish a wordpress blog post in future then you can schedule the publication date rather than saving them as draft and publishing every day or posting every day.

This is a very useful feature in case you wish to write more than one post a day but would like to post them in future on regular itnervals.

To schedule a post in future, you can change the publication date from the Publish tab in right column in Admin.

While you are writing post (of if you have already saved the post then edit it) click on Edit in “Publish immediately Editline.

Wordpress Blog Post Schedule

It will open date edit box. Change the date to be the one when you want to publish it and click on OK.

Wordpress Blog Post ScheduleNext click on the Schedule to accept the changes.

Wordpress Blog Post Schedule

Once it is done you will see that publication date is changed successfully.

Click on Update Post to save any changes and you are done.

Wordpress Blog Post Schedule

Most essenstial wordpress plugins

Following are some of the most essential wordpress plugins which you should have in your wordpress blog.

Essential WordPress Plugins

Following plugins are the most essential which are must for any wordpress blog

1) All in SEO Pack

All in SEO pack plugin is used to convert the dynamic URLs into SEO friendaly URLs and it is one of the most esential wordpress plugin.

Download All in SEO pack plugin

2) Akismet

As soon as you download the WordPress, install it and let Search Engines access your blog you will be flooded with spams in comments. Akistme comes to rescue. This pluging is part of WordPress so you will nothave to install it seperately.

3) Sociable

If you want to promote your blog in Social Media then you need to have this plugin installed. Provides social bookmarking icons added on pages/posts and nice and easy backend features.

Download Sociable Plugin.

4) Google XML Sitemap

Comes handy to generate Google .xml sitemap. This plugin also inform Google and yahoo about the new sitemap wheneve it is generated.

Download Google XML Sitemap.

6) Top Level Category

You will need this when you are using All in SEO pack plugin to make the URL have category name in it

Download Top Level Category.

7) WordPress Automatic Upgrade

Woduldn’t you like to have an automatic wordpress tool to keep your blog updated with the latest WordPress release which keeps on being release ebery month or so? This plugin comes to rescue you from doing manual upgrade which is a real pain.

Download wordpress automatic upgrade plugin.

Optional wordpress Plugins

Following are some of the optional wordpress plugins which you might find useful depending on your requirements.

1) Feedburner feedSmith

2) NextGen Gallery