Sending cross-domain requests using server proxy
Browsers do not allow scripts to send cross-domain requests due to security reasons. This means a script at domain http://www.abc.com cannot send AJAX requests to http://www.xyz.com.
This recipe will show how you can overcome this limitation by using a PHP script on the server side. We will create an example that will search Flickr for images. Flickr will return a JSON, which will be parsed by jQuery and images will be displayed on the page. The following screenshot shows a JSON response from Flickr:
Getting ready
Create a directory for this chapter and name it as Chapter9
. In this directory, create a folder named Recipe1
.
Also get an API key from Flickr by signing up at http://www.flickr.com/services/api/keys/.
How to do it...
Create a file inside the
Recipe1
folder and name it asindex.html
. Write the HTML code to create a form with three fields: tag, number of images, and image size. Also create anul
element inside which the results will be...