我有一個AJAX帖子,發佈網站到PHP,然後返回它,我使用jQuery來查找和返回元素文本。這是工作形式的一些元素,但不是全部,我不明白爲什麼。對於body元標題和標題標記,它將返回undefined。是我的PHP或AJAX職位?jquery .html返回undefined
的jQuery/AJAX
var dataString = name;
//alert (dataString);return false;
$.ajax({
type: "POST",
url: "senddom.php",
data: {"dataString" : dataString },
dataType: "json",
success: function(response) {
var gdom = response;
$('body').append("<p> contents of title:" + $(response).find('Title').html()+ "</p>");
$('body').append("<p> contents of meta:" + $(response).find('meta').html()+ "</p>");
$('body').append("<p> contents of all: " + $(response).find('body').html() + "</p>");
$(response).find('p').each(function() {
$('body').append("<p> contents of p: " + $(this).html() + "</p>");
});
我的PHP
<?php
$site= $_POST['dataString']; // get data
function curl_get($site){
$useragent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$site);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,5);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$data=curl_exec($ch);
curl_close($ch);
return $data;
}
function getdom($site){
$html = curl_get($site);
// Create a new DOM Document
$xml = new DOMDocument();
@$xml->loadHTML($html);
echo json_encode($html);
}
echo getdom($site);
?>
你是否使用Firebug的控制檯來觀察請求/ repsonse? –