MyTetra Share
Делитесь знаниями!
Пример использования XML-RPC в CodeIgniter
Время создания: 12.05.2013 00:48
Раздел: Компьютер - Программирование - Язык PHP - CodeIgniter
Запись: xintrea/mytetra_syncro/master/base/13683052879569visshx/text.html на raw.github.com

Клиентская часть:


var that = this;


alert("Before send, server URL: "+window.location.host);


// Получение XML-кода

$.xmlrpc({

url: 'http://'+window.location.host+'/XmlRpcServer',

methodName: 'getTables',

params: [15, true],

success: function(response, status, jqXHR){ that.successLoad(response, status, jqXHR); },

error: function(jqXHR, status, error) { that.errorLoad(jqXHR, status, error); }

});

alert("After send");


...


// Обработчик получения данны от сервера

this.successLoad=function(response, status, jqXHR)

{

alert("Get tables from server: "+JSON.stringify(response));

alert("Parameter 1: "+response[0]['parameter1']);

alert("Parameter 2: "+response[0]['parameter2']);


}


Серверная часть:


class XmlRpcServer extends MX_Controller

{


function __construct()

{

parent::__construct();


$this->load->library('xmlrpc');

$this->load->library('xmlrpcs');

}



public function index()

{

$config=array();

$config['functions']['getTables'] = array('function' => 'XmlRpcServer.getTables');

$config['object'] = $this;


$this->xmlrpcs->initialize($config);

$this->xmlrpcs->serve();

}


public function getTables($request)

{

$inputParameters = $request->output_parameters();

$responce=array('parameter1'=>$inputParameters[0], 'parameter2'=>$inputParameters[1]);

$responseWrap = array($responce, 'struct');

return $this->xmlrpc->send_response($responseWrap);

}

}


В данном примере на сервер отправляется массив [15, true]. И сервер отвечает, какие параметры были приняты:


Get tables from server: [{"parameter1":"15","parameter2":"1"}]

Parameter 1: 15

Parameter 2: 1


Так же в этом разделе:
 
MyTetra Share v.0.59
Яндекс индекс цитирования