我很困惑我在哪里出错了。我正在对采用 XML 的 PHP 文件进行 AJAX 调用,然后基于该 XML 生成结果并回显它。但是,不会调用 AJAX 处理程序。下面是 JavaScript 和 PHP。
谢谢
JavaScript
$(function() {
$.post("http://thedomain.co.uk/sendxml.php", { xmlData: '
<thisiswhere>
<myxmlis>
</myxmlis>
</thisiswhere>
' }, function(data) {alert(data)}, "xml");
});
PHP
<?php
$xml_builder = $_POST['xmlData'];
// We send XML via CURL using POST with a http header of text/xml.
$ch = curl_init('http://user:pass@myserver.com/api');
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_builder);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, 'http://www.mydomain.co.uk');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ch_result = curl_exec($ch);
curl_close($ch);
echo json_encode(htmlentities($ch_result));
?>