我在尝试使用DOMDocument的PHP函数loadHTML时遇到Mac Yosemith(10.10.4)和Windows 7之间的兼容性错误。 使用Mac,一切正常;使用Windows,Ajax函数失败并自动进入“错误”部分。
这是Ajax函数的代码:
$('form').on("submit", function(event) {
event.preventDefault(); // previene il comportamento di default ed esegue la chiamata ajax
var uri = $("input[name='uri']").val();
if (uri != '') {
$.ajax({
type : 'POST',
url : 'SetFrame.php',
headers : {'Content-Type':'application/x-www-form-urlencoded'},
data : 'uri=' + uri,
dataType : 'json',
success : function (result) {
apriDocumento(result.title, result.url);
},
error : function(jqXHR, textStatus, errorThrown){
alert(jqXHR.status);
alert(jqXHR.status);
alert(jqXHR.responseText);
}
});
} else {
alert('Immetti qualcosa nel campo ricerca!')
}
$("input[name='uri']").prop('value', '');
});
这是回答功能的PHP代码:
<?php
if(isset($_POST['uri'])) {
$url = $_POST['uri'];
$header = get_headers($url, 1);
if(isset($header["X-Frame-Options"])) {
echo 'Warning';
} else {
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($url);
libxml_use_internal_errors(false);
$xpath = new DOMXPath($doc);
$titles = $xpath->query('//title/text()');
foreach ($titles as $t) {
$title = $t->nodeValue;
}
$data = array('title'=>$title, 'url'=>$url);
echo json_encode($data);
} }
?>
有关于这个原因的想法吗?