Mooi initiatief jong’s. Helaas poepie druk op het werk en dus staan vrijwel alle OSM activiteiten tijdelijk in de ijskast, maar ik hoop even snel een bijdrage te kunnen leveren.
IE lijkt dus te bokken op een cross site call, de standaard oplossing hiervoor is een proxy, de mooiste oplossing een javascript/html truuk die in bijvoorbeeld tools als jQuery zit, maar met de standaard oplossing heb ik wat ervaring:
Alle AJAX aanvragen van de browser die naar een pagina buiten de mijndev site gaan moeten via een proxy op de mijndev site gestuurd worden. Zo’n proxy is een simpel (PHP) script dat de request parameters doorstuurt naar de eigenlijke pagina, het antwoord inleest en teruggeeft aan de browser. Het is een omweg maar het werk. Zoek je op ‘cross site’ en ‘proxy’ dan kom je hier genoeg voorbeelden van tegen maar met onderstaand script van phpfour.com heb ik goede ervaringen.
<?php
/**
* Transport for Cross-domain AJAX calls
*
* This is an implementation of a transport channel for utilizing cross-domain
* AJAX calls. This script is passed the data through AJAX along with two special
* hidden field containing the action URL and the http method (GET/POST). It then
* sends the form fields to that URL and returns the response.
*
* @package CrossDomainAjax
* @category CURL
* @author Md Emran Hasan <phpfour@gmail.com>
* @author Lambertus IJsseltein: security fix (allowed domains), flexible headers
* @link http://www.phpfour.com
*/
// The domains we're allowed to contact
$allowedDomains = array('http://gazetteer.openstreetmap.org/',
'http://nominatim.openstreetmap.org/',
'http://dev.openstreetmap.nl/',
'http://www.yournavigation.org/',
'http://yournavigation.org/',
'http://planetosm.oxilion.nl/',
'http://osm.pleiades.uni-wuppertal.de/');
// The actual form action
$action = $_REQUEST['url'];
// Submission method
$method = $_REQUEST['method'];
// Query string
$fields = '';
// Check the url for allowed domains
$fail = true;
foreach ($allowedDomains as $domain)
{
if (strpos(substr($action, 0, strlen($domain)), $domain) !== false)
{
$fail = false;
break;
}
}
if ($fail == true)
{
exit("Domain name '".$action."' not allowed. Access denied.");
}
// Prepare the fields for query string, don't include the action URL OR method
if (count($_REQUEST) > 2)
{
foreach ($_REQUEST as $key => $value)
{
if ($key != 'url' && $key != 'method')
{
$fields .= $key . '=' . rawurlencode($value) . '&';
}
}
}
// Strip the last comma
$fields = substr($fields, 0, strlen($fields) - 1);
// Initiate cURL
$ch = curl_init();
// Do we need to POST of GET ?
if (strtoupper($method) == 'POST')
{
curl_setopt($ch, CURLOPT_URL, $action);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
}
else
{
curl_setopt($ch, CURLOPT_URL, $action . '?' . $fields);
}
// Follow redirects and return the transfer
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "transport.php (CURL)");
// Get result and close cURL
$result = curl_exec($ch);
$curl_info = curl_getinfo($ch);
curl_close($ch);
// Return the response
header("Content-type: ".$curl_info['content_type']);
echo $result;
?>
Plaats het bovenstaande script in http://mijndev.openstreetmap.nl/~ligfietser/fiets/ en vervang de allowedDomains array met de sites die je moet kunnen benaderen. Deze methode van whitelisting is noodzakelijk omdat je site anders misbruikt kan worden voor allerlei illegale activiteiten.
Vervolgens plaats je in de JavaScript de AJAX call de url van dit proxy-script voor de externe url die je nu aanroept. Bijvoorbeeld:
OpenLayers.Request.GET({
url: "proxy.php?url=http://overpass-api.de/api/interpreter/",
callback: onLoadMenu}
);
Het interessante stukje hierin is: “proxy.php?url=”. Hiermee veranderd de externe AJAX call naar een locale AJAX call en dan mag het wel van IE. Ik hoop dat jullie hier wat aan hebben.