2015-09-26 31 views
0

我在我的一個網站上使用了高級頂級菜單:www.vente2site.fr 我需要在我的菜單中的鏈接中添加廣告數量的計數。 所以我沒有任何其他選項,除了jQuery。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}); 
} 

該代碼被稱爲在我的網站的頁腳。

+0

嗨,你們能不能進一步的問題擬訂並在這裏我們可以看到它的網站上? – Saar

回答

0

您需要指定php文件的絕對路徑而不是相對路徑。您可以通過在您提出請求的網址開始處添加一個斜槓/來完成此操作。這是因爲這些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; 
    } 
+1

你在答案中忘記了「/」,但這是解決我的問題的方法。非常感謝 –

+0

Woops,我確定我編輯了答案並添加了斜槓。現在它已經修復了。 – Dola

相關問題