我从 Zillow API 获得 XML 响应,所以我不想要任何 JSON 响应的答案。我想从 Xencall CRM 向 Zillow 发出 API 请求,它给了我错误“访问 XMLHttpRequest 在' https://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=XXXXX ...来自来源“ https://XX.xencall.com ”已被 CORS 策略阻止:没有“Access-Control-Allow-Origin”标头 我只想知道如何在我的请求中添加此 Access-Control-Allow-Origin 标头.这是我的代码:
<p>Click the button to view the Zillow details of the Address</p>
<button onclick="userAction()" type="submit">Find from Zilow</button>
<p id="beds"> </p>
<script>
function userAction() {
const Http = new XMLHttpRequest();
const url='https://www.zillow.com/webservice/GetDeepSearchResults.htm?zws-id=X1-ZXXXXXXXXX&address=(Profile.Address)&citystatezip=(Profile.City) (Profile.State) (Profile.Zip Code)&rentzestimate=true';
Http.open("GET", url);
Http.send();
Http.onreadystatechange = (e) => {
var res=Http.responseText;
var bed1=res.split('<bedrooms>')[1];
var bed= bed1.split('</bedrooms>')[0];
var bath1=res.split('<bathrooms>')[1];
var bath= bath1.split('</bathrooms>')[0];
var zest1=res.split('<zestimate>')[1];
var zest= zest1.split('</amount>')[0];
var zest_rep=zest.replace(/<[^>]*>/g,'');
var zest_40=zest_rep*0.42;
var zest_60=zest_rep*0.62;
var final_html="Bedrooms: "+bed+"<br/>"+"Bathrooms: "+bath+"<br/>"+"Zestimate: "+zest+"<br/>"+"Zestimate Low Range: "+zest_40.toFixed(2)+"<br/>"+"Zestimate High Range: "+zest_60.toFixed(2);
document.getElementById("beds").innerHTML =final_html;
}
};
</script>