2014-05-09 40 views
4

我有一個腳本,可以從我的CMS中獲取數據,然後允許某個人對投票進行投票。該腳本正常工作。不過,我在Firefox中安裝了Ad Block Plus插件。當啓用該功能時,將阻止腳本正確提交表單。它似乎在前端正確提交,但從未在後端註冊。廣告攔截加jQuery腳本?

爲什麼Ad Block Plus會阻止與廣告無關的腳本?

的腳本如下:

$(document).ready(function() { 

    var Engine = { 
     ui: { 
      buildChart: function() { 

       if ($("#pieChart").size() === 0) { 
        return; 
       } 

       var pieChartData = [], 
        totalVotes = 0, 
        $dataItems = $("ul.key li"); 

       // grab total votes 
       $dataItems.each(function (index, item) { 
        totalVotes += parseInt($(item).data('votes')); 
       }); 

       // iterate through items to draw pie chart 
       // and populate % in dom 
       $dataItems.each(function (index, item) { 
        var votes = parseInt($(item).data('votes')), 
         votePercentage = votes/totalVotes * 100, 
         roundedPrecentage = Math.round(votePercentage * 10)/10; 

        $(this).find(".vote-percentage").text(roundedPrecentage); 

        pieChartData.push({ 
         value: roundedPrecentage, 
         color: $(item).data('color') 
        }); 
       }); 

       var ctx = $("#pieChart").get(0).getContext("2d"); 
       var myNewChart = new Chart(ctx).Pie(pieChartData, {}); 

      }, // buildChart 

      pollSubmit: function() { 

       if ($("#pollAnswers").size() === 0) { 
        return; 
       } 

       var $form = $("#pollAnswers"), 
        $radioOptions = $form.find("input[type='radio']"), 
        $existingDataWrapper = $(".web-app-item-data"), 
        $webAppItemName = $existingDataWrapper.data("item-name"), 
        $formButton = $form.find("button"), 
        bcField_1 = "CAT_Custom_1", 
        bcField_2 = "CAT_Custom_2", 
        bcField_3 = "CAT_Custom_3", 
        $formSubmitData = ""; 

       $radioOptions.on("change", function() { 

        $formButton.removeAttr("disabled"); // enable button 

        var chosenField = $(this).data("field"), // gather value 
         answer_1 = parseInt($existingDataWrapper.data("answer-1")), 
         answer_2 = parseInt($existingDataWrapper.data("answer-2")), 
         answer_3 = parseInt($existingDataWrapper.data("answer-3")); 

        if (chosenField == bcField_1) { 
         answer_1 = answer_1 + 1; 
         $formSubmitData = { 
          ItemName: $webAppItemName, 
          CAT_Custom_1: answer_1, 
          CAT_Custom_2: answer_2, 
          CAT_Custom_3: answer_3 
         }; 
        } 

        if (chosenField == bcField_2) { 
         answer_2 = answer_2 + 1; 
         $formSubmitData = { 
          ItemName: $webAppItemName, 
          CAT_Custom_1: answer_1, 
          CAT_Custom_2: answer_2, 
          CAT_Custom_3: answer_3 
         }; 
        } 

        if (chosenField == bcField_3) { 
         answer_3 = answer_3 + 1; 
         $formSubmitData = { 
          ItemName: $webAppItemName, 
          CAT_Custom_1: answer_1, 
          CAT_Custom_2: answer_2, 
          CAT_Custom_3: answer_3 
         }; 
        } 

        prepForm($formSubmitData); 

       }); 


       function prepForm(formSubmitData) { 

        $formButton.click(function(e) { 
         e.preventDefault(); 
         logAnonUserIn("anon", "anon", formSubmitData); // log user in 

        }); // submit 

       } // prepForm 

       function logAnonUserIn(username, password, formSubmitData) { 
        $.ajax({ 
         type: 'POST', 
         url: '/ZoneProcess.aspx?ZoneID=-1&Username=' + username + '&Password=' + password, 
         async: true, 
         beforeSend: function() {}, 
         success: function() {}, 
         complete: function() { 
          fireForm(formSubmitData); 
         } 
        }); 
       } // logAnonUserIn 

       function fireForm(formSubmitData) { 
        // submit the form 

        var url = "/CustomContentProcess.aspx?A=EditSave&CCID=13998&OID=3931634&OTYPE=35"; 

        $.ajax({ 
         type: 'POST', 
         url: url, 
         data: formSubmitData, 
         async: true, 
         success: function() {}, 
         error: function() {}, 
         complete: function() { 
          window.location = "/"; 
         } 
        }); 
       } 

      } // pollSubmit 

     } // end ui 

    }; 

    Engine.ui.buildChart(); 
    Engine.ui.pollSubmit(); 

}); 
+0

我也看到了Chrome的行爲。它返回net :: ERR_BLOCKED_BY_CLIENT,但我不知道爲什麼。 – sdespont

+0

+1不發送垃圾郵件「var」。注意:當adBlockPlus獲取其文件路徑中包含文件夾/ ad /的圖像時,我遇到過這種問題,它可能會使您處於軌道上... – nicolallias

+0

查詢字符串/文件名稱中的某些內容可能與adblocker文件過濾器中的規則匹配名單。 – epascarello

回答

1

事實證明easylist包含此過濾器:

.aspx?zoneid= 

這就是爲什麼我的腳本被阻止。

有人告訴我,我可以試試這個異常過濾器:

@@||example.com/ZoneProcess.aspx?*$xmlhttprequest 

我也可以問easylist添加一個例外。

Answer comes from Ad Block Plus Forums.

+0

是的,加入本地例外並不能幫助個人用戶。 – markj