我使用Savant主题来构建一个网站,我在一些页面上使用以下JS代码(使用自定义字段,我使用字段名称"示例"然后在值中指定JS)以获取属性列表通过调用API并接收JSON数据。
JS代码:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js" type="text/javascript" language="JavaScript"></script>
<!--<script type="text/javascript" src="http://www.bedstax.com/realtorData/featuredCommunities.php?state=FL&area=Bonita Springs%20/%20Estero"></script>
//-->
<script type="text/javascript">
var state = 'FL';
var area = 'Bonita Springs / Estero';
var idx = '583';
var agent = '1212';
var domain = 'xxx';
function setCommunity(community,communityName) {
var cookieSet = window.state + "::" + window.area + "::" + window.idx + "::" + window.agent + "::" + window.domain + "::" + community + '::' + communityName;
document.cookie='idxCookie=' + cookieSet + '; path=/';
document.location.href = '/featured-communities-info';
}
jQuery(document).ready(function() {
jQuery.ajax({
url:"http://bedstax.com/realtorData/newFeatComm.php?state=" + window.state + "&area=" + window.area + "&idx=" + window.idx,
dataType: 'JSONP', // Notice! JSONP <-- P
success:function(json){
$('.output').html(json);
},
error:function(){
alert("Error");
},
});
});
</script>
<div class="output">
</div>
删除自定义字段可启用所有javascript,但这段代码可以正常工作。我正在做什么有什么问题,因为它会禁用页面上的所有JS。
任何帮助将不胜感激。
答案 0 :(得分:2)
如果包含jquery,则运行下面的代码。
var state = 'FL';
var area = 'Bonita Springs / Estero';
var idx = '583';
var agent = '1212';
var domain = 'xxx';
function setCommunity(community,communityName) {
var cookieSet = window.state + "::" + window.area + "::" + window.idx + "::" + window.agent + "::" + window.domain + "::" + community + '::' + communityName;
document.cookie='idxCookie=' + cookieSet + '; path=/';
document.location.href = '/featured-communities-info';
}
jQuery(document).ready(function() {
jQuery.ajax({
url:"http://bedstax.com/realtorData/newFeatComm.php?state=" + window.state + "&area=" + window.area + "&idx=" + window.idx,
dataType: 'JSONP', // Notice! JSONP <-- P
success:function(json){
$('.output').html(json);
},
error:function(){
alert("Error");
},
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="output">
</div>
&#13;
答案 1 :(得分:0)
我通过将jquery版本从1.5.1升级到1.7.1找到了解决此问题的方法。