Chrome扩展转移到manifest 2 -没有ajax响应

时间:2022-04-18 20:17:51

Hayush! Been trying to transfer my Chrome extension to manifest 2. Everything is working except for one script which calls an ajax. I have a variable that contains a JSON content which needs to be transferred to the server.

Hayush !一直在尝试将我的Chrome扩展转移到manifest 2。除了一个调用ajax的脚本之外,所有的东西都在工作。我有一个包含JSON内容的变量,需要传输到服务器。

function sendlist(list){

jsontext = JSON.stringify(list);

$.ajax({
        url: amfurl + "user/listbookmarks/",
            dataType: 'text json',
        async: true,
        type: 'POST',
        processData: false,
            data: {'folders': jsontext}, 

        success: function(data){
            $('#importing').css('display','none');
            $('#importdone').css('display','block');
            console.log(data);      
        },
        error: function(xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
        alert(err.Message);
}
});  
}

For some reason the ajax part is not executed at all. No error message was triggered, nor in the server error log.

出于某种原因,ajax部分根本没有执行。没有触发错误消息,服务器错误日志中也没有。

All of the inline scripts and scripts in general were included in the popup.js. So it's probably not the issue.

js中包含了所有的内联脚本和脚本。所以这可能不是问题所在。

Any thoughts?

任何想法吗?

Thanks!

谢谢!

The following code works perfectly on previous manifest

下面的代码在以前的清单上工作得很好

function importbookmarks(){
$('#formadd').css('display','none');
$('#importing').css('display','block');
_gaq.push(['_trackEvent', 'chromextension','importbookmarks', username]);
 chrome.bookmarks.getTree(function(bookmarks) {
        sendlist(bookmarks);
   });
}


function sendlist(list){
jsontext = JSON.stringify(list);
$.ajax({
        url: amfurl + "user/listbookmarks/",
            dataType: 'text json',
        async: true,
        type: 'POST',
    //  processData: false,
            data: {'folders': jsontext}, 

        success: function(data){
            $('#importing').css('display','none');
            $('#importdone').css('display','block');
            console.log(data);

        }
});  
}

1 个解决方案

#1


0  

The problem wasn't with the function. The button execution wasn't calling it correctly. Here is the code I used to get the function to work in manifest 2

问题不在于这个函数。按钮执行没有正确调用它。这是我用来让函数在清单2中工作的代码

document.addEventListener("DOMContentLoaded", function () {
    document.getElementById("import-bookmarks").addEventListener("click", function () {
        importbook();return;
    });

#1


0  

The problem wasn't with the function. The button execution wasn't calling it correctly. Here is the code I used to get the function to work in manifest 2

问题不在于这个函数。按钮执行没有正确调用它。这是我用来让函数在清单2中工作的代码

document.addEventListener("DOMContentLoaded", function () {
    document.getElementById("import-bookmarks").addEventListener("click", function () {
        importbook();return;
    });