Jquery 代码在特定页面上不起作用

Jquery code not working on specific page

我在我的网站之一中使用高级顶部菜单:www.vente2site.fr 我需要在我的菜单中的链接中添加广告数量。 所以除了 jquery.

我别无选择

在我的主页上:https://www.vente2site.fr/ - 计数工作正常,所有页面都是这样,除了:

https://www.vente2site.fr/e-commerces-sites-marchands-en-vente-a-ceder/2064-pret-a-porter-feminin-et-accessoires-de-modemod-elles.html - 我已设置条件以防止此页面上的代码 运行 因为它导致了 302 重定向。

产品页面(prestashop 1.4.8)用作展示广告的页面。

下面是我使用的代码:

function replacetext(url, inittext, text, value) {
        var foundin = $('.adtm_elements_5 *:contains("' + text + '")');
        //foundin.html("<table><tr><td style='vertical-align:middle'>" + inittext + </a></td></tr></table>");
        foundin.html("<a href='" + url + "'>" + inittext + " ( <b style='color:#01b196;padding:0px!important;font-weight:bold;margin:0px!important;'>" + value + "</b> )</a>");
        return false;
}

function replacetextDataroom(url, inittext, text, value) {
        var foundin = $('.adtm_elements_11 *:contains("' + text + '")');
        //foundin.html("<table><tr><td style='vertical-align:middle'>" + inittext + </a></td></tr></table>");
        foundin.html("<a href='" + url + "'>" + inittext + " ( <b style='color:#01b196;padding:0px!important;font-weight:bold;margin:0px!important;'>" + value + "</b> )</a>");
        return false;
}

function replacecount(url, inittext, text, id) {
        var vars = new Object();
        vars['cat'] = id;


        $.ajax({
            type: "POST",
            url: "getComptage.php",
            data: vars,
            success: function (msg) {
                replacetext(url, inittext, text, msg);
            }
        });
        return false;
}

function getdataroom(url, inittext, text, id) {
        var vars = new Object();
        vars['idc'] = id;

        $.ajax({
            type: "POST",
            url: "getDataroomAccessCount.php",
            data: vars,
            success: function (msg) {
                replacetextDataroom(url, inittext, text, msg);
            }
        });
        return false;
}

if(window.location.href.indexOf("e-commerces-sites-marchands-en-vente-a-ceder") > -1 || 
   window.location.href.indexOf("sites-internet-e-business-en-vente") > -1 || 
   window.location.href.indexOf("medias-digitaux") > -1 || 
   window.location.href.indexOf("saas") > -1 ||  
   window.location.href.indexOf("applications-ios-android-fb-en-vente") > -1){

}else{
        replacecount('https://www.vente2site.fr/5-e-commerces-sites-marchands-en-vente-a-ceder','Sites Marchands','(CCC1)', 5);
        replacecount('https://www.vente2site.fr/6-sites-internet-e-business-en-vente','Services en ligne','(CCC2)', 6);
        replacecount('https://www.vente2site.fr/172-medias-digitaux','Médias digitaux','(CCC3)', 172);
        replacecount('https://www.vente2site.fr/173-saas','SaaS','(CCC4)', 173);
        replacecount('https://www.vente2site.fr/7-applications-ios-android-fb-en-vente','Apps Mobiles','(CCC5)', 7);

        getdataroom('https://www.vente2site.fr/repreneurdataroom.php?opp=view','Datarooms auquelles jai acces','(CCC6)', {$idclient});
 }

此代码在我网站的页脚中调用。

您需要指定 php 文件的绝对路径而不是相对路径。您可以通过在要向其发出请求的 URL 的开头添加斜杠 / 来实现。这是因为这些 php 文件位于您域的根目录中。

所以你需要把你的函数改成这样:

function replacecount(url, inittext, text, id) {
        var vars = new Object();
        vars['cat'] = id;


        $.ajax({
            type: "POST",
            url: "/getComptage.php",
            data: vars,
            success: function (msg) {
                replacetext(url, inittext, text, msg);
            }
        });
        return false;
    }

 function getdataroom(url, inittext, text, id) {
        var vars = new Object();
        vars['idc'] = id;

        $.ajax({
            type: "POST",
            url: "/getDataroomAccessCount.php",
            data: vars,
            success: function (msg) {
                replacetextDataroom(url, inittext, text, msg);
            }
        });
        return false;
    }