我正在开发一个cURL和ajaxsoap请求来获取XML/WSDL数据。该请求有效地获取了我想要的数据,我正在使用wp\\u send\\u json\\u success();操纵响应。我收到的答复如下:
我不确定如何解析数据。以下是我在这方面所做的努力:
<?php /** Set Up Plugin */
function clientside() {
if ($_SERVER[\'REQUEST_METHOD\'] === \'POST\') {
$var = $_POST[\'var\'];
$var = $_POST[\'var\'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "http://api/?wsdl=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER => array(
"SOAPAction: \\"urn:xmlname\\"",
"Authorization: Basic XXXxxx",
"Cache-Control: no-cache",
"Postman-Token: XXXxxx",
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
wp_send_json_error([ "error" => $err]);
} else {
wp_send_json_success([ "data" => $response ]);
}
}
}
/** admin-ajax set up */
?>
Ajax:
jQuery(function ($) {
$(\'#search_form\').submit(function (event) {
var $this = $(this);
// initialize form data
var data = $this.serializeArray();
data.push({
name: "action",
value: "clientside",
});
event.preventDefault();
$.ajax({
// method for paremeters
method: \'POST\',
url: clientside.url,
data: $.param(data),
success: function (data) {
console.log(data);
// make stuff happen
});
},
error: function(){
alert(\'An error has occured while processing XML file.\');
},
});
});
});