http://www.phpfour.com/blog/2008/03/06/cross-domain-ajax-using-php/

<?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 <[EMAIL PROTECTED]>
 * @link        http://www.phpfour.com
 */

// The actual form action
$action = $_REQUEST['url'];

// Submission method
$method = $_REQUEST['method'];

// Query string
$fields = '';

// 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);

// Get result and close cURL
$result = curl_exec($ch);
curl_close($ch);

// Return the response
echo $result;

?>

philosaur wrote:
> Hi!
>
> I'm writing an OGC/WMS Viewer using jQuery.  One task I need to
> accomplish involves making a getCapabilities request against a Web
> Mapping Service, which responds with some XML.
>
> I know that the $.ajax function allows me to get JSON from another
> domain, but is there a way to get XML from another domain?  I've tried
> various permutations of data types, and the $.ajax call with the
> "jsonp" call gets closest--it returns the XML, but since it's not true
> JSON, the browser complains.
>
> Is my only option to use a proxy web service to access the XML?
>
> Thanks!
>
>   

Reply via email to