Php CI,如何在控制器中生成xml代码?
事实上,我正在编写Ajax代码,并希望 控制器文件中的xml代码 怎么可能编写xml代码呢Php CI,如何在控制器中生成xml代码?,php,xml,codeigniter,Php,Xml,Codeigniter,事实上,我正在编写Ajax代码,并希望 控制器文件中的xml代码 怎么可能编写xml代码呢 在控制器文件中检查以下链接 http://ellislab.com/codeigniter/user-guide/libraries/xmlrpc.html https://github.com/EllisLab/CodeIgniter/wiki/XML-generator-library 您想要的示例: 在CI控制器中: class XML extends CI_Controller { pub
在控制器文件中检查以下链接
http://ellislab.com/codeigniter/user-guide/libraries/xmlrpc.html
https://github.com/EllisLab/CodeIgniter/wiki/XML-generator-library
您想要的示例:
在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
});
});
是,可以在控制器中生成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>';
为什么数据类型是字符串而不是xml?我还必须编写一个xml代码,并将其赋给变量$xml_code,对吗?@user2522245,是的,类似于这样的东西,您需要将其传递给变量并回显它。如果您有firebug,可以在控制台中检查ajax的响应。。然后试着探索让你学习:)非常感谢:)我终于明白了~
$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);