实际上我正在编写Ajax并希望创建一个 控制器文件中的xml代码。
怎么可能编写xml代码 在控制器文件中?
答案 0 :(得分:1)
你想要的样本: 在CI控制器中:
class XML extends CI_Controller {
public function my_function(){
//your xml code here
echo $xml_code; //echo your output
}
}
并且在你的脚本中你可能会这样:
$(function() {
$.ajax({
url: '/XML/my_function/',
type: 'POST',
dataType: 'string',
success: function(response){
//do what you want for response
});
});
答案 1 :(得分:0)
检查以下链接。
http://ellislab.com/codeigniter/user-guide/libraries/xmlrpc.html
https://github.com/EllisLab/CodeIgniter/wiki/XML-generator-library
答案 2 :(得分:0)
是的,可以在控制器中生成xml文件:
只需在变量
中创建xml $xml_builder = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Transact xmlns="http://Exxxx/xxxTopUp">
<LoginInfo>
<AccountID>' . $account_id . '</AccountID>
<Username>' . $username . '</Username>
<Password>' . $password . '</Password>
<BranchID>' . $branch_id . '</BranchID>
</LoginInfo>
<Telco>' . $telco . '</Telco>
<CellphoneNo>' . $cellphone_no . '</CellphoneNo>
<ExtTag>' . $Ext_tag . '</ExtTag>
<Amount>' . $amount . '</Amount>
<Token>' . $token . '</Token>
</Transact>
</soap:Body>
</soap:Envelope>';
然后我们使用带有text / xml的http标头的POST通过CURL发送XML。
$url = "http://xxxxxxxxx.com/xxxtopup/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ch_result = curl_exec($ch);