Monday 12 September 2011

XHR2

Recently I used XHR2 for the CSSA new website. Basically, XHR2 enhances XHR with new features, such as cross-origin requests. This means you can make an XHR request across domains, but only if the server you're connecting to allows it.

This means the server needs to respond with a CORS (Cross-Origin Resource Sharing) header. For PHP, you can add the following lines at the beginning of the .php file:

<?php
header('Access-Control-Allow-Origin: *');
?>

'*' means it allows any origin to access the resource.

References:
https://developer.mozilla.org/en/HTTP_access_control#Access-Control-Allow-Origin
http://html5doctor.com/methods-of-communication/

No comments :

Post a Comment