[dokuwiki] ajax consuming cross domain webservice

  • From: James Lin <guanfenglin@xxxxxxxxx>
  • To: dokuwiki@xxxxxxxxxxxxx
  • Date: Fri, 27 Mar 2009 09:57:09 +1300

Hi Guys,

I was coding some ajax stuff consuming cross domain webservices, I was
having trouble with the cross domain security issue, my solution was
creating a generic proxy php class with uses nusoap to output the xml
result, then in the script.js file, I used the xml2json library to convert
the xml into json objects. I am not sure if this is the correct approach,
could someone please verify this? If this is the correct way to do it, is it
worth to put onto the developement wiki page for people who are new to this?

see partial code below:

proxy.php
<?php
require_once ('nusoap/nusoap.php');

$client = new nusoap_client($_REQUEST['url'], true);
$operation = $_REQUEST['op'];
unset($_REQUEST['url']);
unset($_REQUEST['op']);
$result = $client->call($operation, $_REQUEST);
echo $client->document;
?>

script.js

...
function searchPeople()
{
        $('searchStatus').innerHTML = 'Searching';
        var url = 'lib/plugins/aclmadeeasy/proxy.php?url='+escape('
http://test/PersonFinderPOC/service.asmx?wsdl')+'&op=search&searchQuery='+escape($('advancedWho').value
);
        http.open("GET", url, true);
        http.onreadystatechange = callBackResult;
        http.send(null);
}

function callBackResult()
{
        if (http.readyState == 4)
        {
                var result = xml2json.parser(http.responseText);
                ...
        }
}

regards

James Lin

Other related posts: