所以我一定错过了什么。我可以执行以下操作来检索zpid和zestimate没问题:
$zdata->response->zpid; //zpid
$zdata->response->zestimate->amount; //zestimate
但是当我尝试似乎明显等同于检索地址的一部分时:
$zdata->response->address->street;
$zdata->response->address->city;
它都不起作用!为什么??显然,我必须在这里遗漏一些东西。下面是我的整个代码
<?php
$zillow_id = '1234';
$search = $_POST['address'];
$citystate = $_POST['csz'];
$address = urlencode($search);
$citystatezip = urlencode($citystate);
$url = "http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=".$zillow_id."&address=".$address."&citystatezip=".$citystatezip;
$result = file_get_contents($url);
$data = simplexml_load_string($result);
$zpidNum = $data->response->results->result[0]->zpid;
$zurl = "http://www.zillow.com/webservice/GetZestimate.htm?zws-id=".$zillow_id."&zpid=".$zpidNum;
$zresult = file_get_contents($zurl);
$zdata = simplexml_load_string($zresult);
//echo $zdata->response->zestimate->amount;
//$zestimate=$zdata->response->zestimate->amount;
$zstreet=$zdata->response->address->street;
echo $street;
?>
查看 Zillow 自己的文档中所见的 XML 输出,我遵循相同的模式来尝试获取街道以获取热情。我对使用 XML 不是很熟悉,所以很可能我遗漏了一些东西。
所以我在控制台中收到一个错误,显示以下内容:
未捕获的 SyntaxError:意外的令牌 T
'T' 似乎是输入的街道的第一个字母,因为它会相应变化。也许这可以对这个问题有所启发?
我也会发布我的 AJAX,但我不知道为什么会有问题。如上所述,我能够很好地显示 ZPID 和 Zestimate,只是地址不起作用。
AJAX/JS:
function validateAddress(){
var address = document.getElementById('address').value;
var csz = document.getElementById('city_state_zip').value;
if (address == null || address == "" || csz == null || csz == "") {
return false;
}
else{
getZestimate(address,csz);
}
}
function getZestimate(address,csz){
var xmlhttp = new XMLHttpRequest();
var userdata = "address="+address+"&csz="+csz;
xmlhttp.open("POST","../wp-content/themes/realhomes/submit_address.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
//retrieve = JSON.parse(xmlhttp.responseText);
retrieve = xmlhttp.responseText;
document.getElementById("zestimateArea").innerHTML = '<div id="zillowWrap"><a href="http://www.zillow.com"><img src="http://www.zillow.com/widgets/GetVersionedResource.htm?path=/static/logos/Zillowlogo_150x40.gif" width="150" height="40" alt="Zillow Real Estate Search" id="ZillowLogo" /></a><span id="zestimateTag">Zestimate®</span></div><span id="zestimatePrice">'+retrieve+'</span><div id="zillowDisclaimer"><span>© Zillow, Inc., 2006-2014. Use is subject to <a href="http://www.zillow.com/corp/Terms.htm">Terms of Use</a></span><span>What’s a <a href="http://www.zillow.com/wikipages/What-is-a-Zestimate">Zestimate?</a>';
}
else{
document.getElementById("zestimateArea").innerHTML = "Error!"
}
}
xmlhttp.send(userdata);
document.getElementById("zestimateArea").innerHTML = "Generating...";
return false;
}