I'm facing a compatibility error between Mac Yosemith (10.10.4) and Windows 7 while trying to use the PHP function loadHTML of DOMDocument. Using Mac, everything works fine; using Windows, the Ajax function fails and goes automatically in the "error" part.
Here's the code of the Ajax function:
$('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', '');
});
And here's the PHP code that answers the function:
<?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);
} }
?>
Any idea about the reason?