简体   繁体   English

Wordpress和JS冲突

[英]Wordpress and JS Conflict

Firstly here's the URL: http://isotopethemes.com/js-conflict/community-listings/naples/ 首先是URL: http//isotopethemes.com/js-conflict/community-listings/naples/

I'm using Savant Theme to build a website, in the above page I use BedStax to get list of areas. 我正在使用Savant Theme来建立一个网站,在上面的页面中我使用BedStax来获取区域列表。 To get list of areas I use the following code as custom field: 要获取区域列表,我使用以下代码作为自定义字段:

<!--<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 = 'Naples';
var idx = '583';
var agent = 'xxx';
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>

The issue is wherever there this code generates list of areas all JS on the page stops working, on the above linked page the search bar pop slide down does not work. 问题是,无论何处此代码生成区域列表,页面上的所有JS都停止工作,在上面的链接页面上,搜索栏弹出向下滑动不起作用。 On this page: http://isotopethemes.com/js-conflict/about-2/ click the search bar and it slides down, same with the plus symbol on the top right corner. 在此页面上: http//isotopethemes.com/js-conflict/about-2/单击搜索栏并向下滑动,与右上角的加号一致。

I've looked into the console and get this error: Uncaught TypeError: this.on is not a function (line 16 jquery.min.js). 我查看了控制台并得到了这个错误:Uncaught TypeError:this.on不是一个函数(第16行jquery.min.js)。

I've been struggling for days, I can give you the wp-login id and password if you want, any help would be appreciate :) 我已经苦苦挣扎了几天,如果你愿意,我可以给你wp登录ID和密码,任何帮助都会很感激:)

Update 更新

This ended up being (after chatting for a minute) the jquery version. 这最终成为(在聊了一分钟之后)jquery版本。 Updating to 1.7 proved to be the solution. 更新到1.7证明是解决方案。 (NOTE: 2.0.1 would break it again, so 1.7 was the sweet spot). (注意:2.0.1会再次打破它,所以1.7是最佳点)。

We left the encapsulation in the code, so I'm leaving it in the answer as well. 我们在代码中留下了封装,所以我也将其留在了答案中。


Try encapsulating your jquery and see if that helps at all. 尝试封装你的jquery,看看是否有帮助。

(function($){
    $(function(){  

        $.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");
            }
        });

    });   
})(jQuery); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM