插件在本地不起作用,但在服务器上起作用

时间:2015-03-24 作者:W442

这是一个万岁的机会,但我很感激任何能为我指明正确方向的想法。

我为我的wordpress网站创建了一个“插件”。我有一个位于服务器上的实时站点和一个安装在Xampp本地的站点。这个插件在live server站点上运行得很好,但当我将其克隆到本地托管站点时,它就不起作用了。

我真的需要这个在当地工作,因为很多原因,我可能会让你厌烦解释。

更多详细信息:当我在本地站点上打开Chrome控制台时,出现一个错误,说明:

Failed to load resource: the server responded with a status of 404(Not Found) http://localhost:8080/rol/Desktop/sitefolder/htdocs/wordpress/wp-content/plugins/wpnotebook/ajax.php?_=1427163308124&action=1tabs

我的想法是,编码中有一个错误,使其从我的计算机上的物理文件夹中提取,而不是尝试从以下文件夹中提取:

http://localhost:8080/wordpress/wp-content/plugins/wpnotebook/ajax.php?_=1427163308124&action=1tabs

如果是这样的话,我只是不知道该怎么解决。以下是ajax选项卡脚本的代码:

jQuery(document).ready(function($) {
    /*$(document).ready(function(){*/
    /* This code is executed after the DOM has been completely loaded */
    var dirurll = jQuery(\'#dirurl\').val();
    var bkid = jQuery(\'#idbook\').val();
    //alert(dirurll);
    jQuery.ajax({
       type: "GET",
       url: "/"+dirurll+"/ajax.php",
       data: "action="+bkid+"tabs",
       cache: false,
       dataType: "json",
       success: function(Tabs){

            jQuery.each(Tabs, function(i){

                /* Sequentially creating the tabs and assigning a color from the array: */
                var tab = jQuery(\'<li id="Tab-\'+Tabs[i].tab_id+\'" class="tabItem">\'+
                                \'<div class="tabTitle">\'+
                                    \'<a href="#" class="tab"><span class="left"></span><div class="tabName">\'+Tabs[i].name+\'</div><span class="right"></span></a>\'+
                                \'</div>\'+
                                \'<div class="tabCreated">\'+Tabs[i].date_created+\'</div>\'+
                            \'</li>\');

                /* Adding the tab to the UL container: */
                jQuery(\'#tabRow\').append(tab);

            });

            jQuery(\'#tabRow\').sortable({
                update      : function(event, ui){      // The function is called after the tabs are rearranged

                            // The toArray method returns an array with the ids of the tabs

                            var arr = jQuery("#tabRow").sortable(\'toArray\');
                            // Striping the Tab- prefix of the ids:
                            arr = jQuery.map(arr,function(val,key){
                                return val.replace(\'Tab-\',\'\');
                            });

                            // Saving with AJAX
                            jQuery.get(\'/\'+dirurll+\'/ajax.php\',{action:\'rearrangeTabs\',positions:arr,rand:Math.random()});
                        }
            });

            /* Caching the tabs into a variable for better performance: */
            var the_tabs = $(\'.tab\');

            the_tabs.live(\'click\',function(e){
                /* If it is currently active, return false and exit: */
                if($(this).is(\'.activeTab\')) return false;

                jQuery(\'#contentHolder\').empty();

                /* "this" points to the clicked tab hyperlink: */
                currentTabID = $(this).closest(\'.tabItem\').attr(\'id\').replace(\'Tab-\',\'\');

                /* Set the current tab: */
                jQuery(\'a.tab\').removeClass(\'activeTab\');
                jQuery(this).addClass(\'activeTab\');
                jQuery(\'#pageList\').empty();
                jQuery.getJSON(\'/\'+dirurll+\'/ajax.php\',{"action":bkid+"pages","tab_id":currentTabID,rand:Math.random()},function(Pages){

                    jQuery.each(Pages, function(i){

                        /* Sequentially creating the pages and assigning a color from the array: */
                        var pageItem = jQuery(\'<li id="Page-\'+Pages[i].page_id+\'" class="pageItem">\'+
                                        \'<div class="pageTitle">\'+
                                            \'<a href="" id="Page-\'+Pages[i].page_id+\'" class="notepage">\'+
                                            \'<span class="left"></span><span class="pageName">\'+Pages[i].name+
                                                \'</span><span class="right"></span></a>\'+
                                        \'</div>\'+
                                        \'<div class="pageCreated">\'+Pages[i].date_created+\'</div>\'+
                                        \'<div class="columns">\'+Pages[i].columns+\'</div>\'+
                                    \'</li>\');

                        /* Setting the page data for each hyperlink: */
                        pageItem.find(\'a\').data(\'page\',\'/\'+dirurll+\'/ajax.php\'+\'?action=\'+bkid+\'lists&page_id=\'+Pages[i].page_id);
                        makeTabsDroppable();

                        /* Adding the tab to the UL container: */
                        jQuery(\'#pageList\').append(pageItem).fadeIn(\'fast\');
                    });  // close $.each(Pages)
                    // add link to create a new page
                    var newPage = jQuery(
                        \'<li id="newPageItem">\'+
                            \'<abbr title="\'+_(\'New Page\')+\'"><a href="" class="notebookIcons newPage">\'+
                            \'</a></abbr>\'+
                        \'</li>\');

                    jQuery(\'#pageList\').append(newPage);
                    makePagesDroppable();

                    // Make the first page the active page
                    clickPage();  // function located in notebook.php

                    jQuery(\'#pageList\').sortable({
                        items       : \'li.pageItem\',
                        update      : function(event, ui){      // The function is called after the tabs are rearranged

                                    // The toArray method returns an array with the ids of the tabs

                                    var arr = jQuery("#pageList").sortable(\'toArray\');
                                    // Striping the Tab- prefix of the ids:
                                    arr = jQuery.map(arr,function(val,key){
                                        return val.replace(\'Page-\',\'\');
                                    });

                                    // Saving with AJAX
                                    jQuery.get(\'/\'+dirurll+\'/ajax.php\',{action:\'rearrangePages\',positions:arr,rand:Math.random()});
                        }
            });


                });  // close $.get("ajax.php")


                e.preventDefault();
            })


            jQuery(\'a.notepage\').live(\'click\',function(e){

                /* "this" points to the clicked page hyperlink: */
                var element = $(this);

                /* If it is currently active, return false and exit: */
                if($(this).is(\'.activePage\')) return false;

                /* Set the current page: */
                jQuery(\'a.notepage\').removeClass(\'activePage\');
                jQuery(this).addClass(\'activePage\');

                /* Checking whether the AJAX fetched page has been cached: */
                if(!element.data(\'cache\'))
                {   
                    /* If no cache is present, show the gif preloader and run an AJAX request: */
                    jQuery(\'#contentHolder\').html(\'<img src="theme/default/images/ajax_preloader.gif" width="64" height="64" class="preloader" />\');

                    jQuery.get(element.data(\'page\'),{\'rand\':Math.random()},function(msg){
                        jQuery(\'#contentHolder\').html(msg);

                    });
                }
            })  //close .notepage live click

            /* Emulating a click on the first tab so page list is not empty: */
            clickTab(); // function located in notebook.php


// Listen for click on New Tab icon
            jQuery(\'.newTab\').live(\'click\',function(e){
                addTab(\'newTab\',0);


            });  // close #newTab click

            // Listen for click on Add Page icon
            jQuery(\'.newPage\').live(\'click\',function(e){
                addPage(\'newPage\', currentTabID);
                e.preventDefault();

                });  // close #newTab click


       } // closing ajax success:

    });  // close ajax


});

function addTab(action, id) {
                var dirurlll = jQuery(\'#dirurl\').val();
                var d = new Date();
                var curr_date = d.getDate();
                var curr_month = d.getMonth();
                curr_month++;
                var curr_year = d.getFullYear();
                var curr_hour = d.getHours();
                var curr_min = d.getMinutes();

                currentDate = curr_year + "-" + curr_month + "-" + curr_date + " " + curr_hour + ":" + curr_min ;


                jQuery.getJSON(\'/\'+dirurlll+\'/ajax.php\',{\'action\':action,\'id\':id,rand:Math.random()},function(Tabs){

                    jQuery.each(Tabs, function(i){

                        var tabCreated = Tabs[i].date_created;
                        tabCreated = tabCreated.substring(0,tabCreated.length-3); // remove the seconds section from the date

                        /* Build the new tab and append it to the tabRow */
                        var tab = jQuery(
                        \'<li id="Tab-\'+Tabs[i].tab_id+\'" class="tabItem">\'+
                            \'<div class="tabTitle">\'+
                                \'<a href="#" class="tab"><span class="left"></span><div class="tabName">\'+Tabs[i].name+\'</div><span class="right"></span></a>\'+
                            \'</div>\'+
                            \'<div class="tabCreated">\'+tabCreated+\'</div>\'+
                        \'</li>\');

                        /* Adding the tab to the UL container: */
                        jQuery(\'#tabRow\').append(tab);

                    }); // close .each loop
                    makeTabsDroppable();
                });  // close newTab ajax call
}

function addPage(action,id) {
    var dirurlll = jQuery(\'#dirurl\').val();
    var bkid = jQuery(\'#idbook\').val();
    var d = new Date();
    var curr_date = d.getDate();
    var curr_month = d.getMonth();
    curr_month++;
    var curr_year = d.getFullYear();
    var curr_hour = d.getHours();
    var curr_min = d.getMinutes();

    currentDate = curr_year + "-" + curr_month + "-" + curr_date + " " + curr_hour + ":" + curr_min ;

        jQuery.getJSON(\'/\'+dirurlll+\'/ajax.php\',{\'action\':action,\'id\':id,rand:Math.random()},function(Pages){

            jQuery.each(Pages, function(i){

                var pageCreated = Pages[i].date_created;
                pageCreated = pageCreated.substring(0,pageCreated.length-3); // remove the seconds section from the date

                /* Sequentially creating the pages and assigning a color from the array: */
                var pageItem = jQuery(\'<li id="Page-\'+Pages[i].page_id+\'" class="pageItem">\'+
                                \'<div class="pageTitle">\'+
                                \'<a href="" id="Page-\'+Pages[i].page_id+\'" class="notepage">\'+
                                \'<span class="left"></span><span class="pageName">\'+Pages[i].name+
                                    \'</span><span class="right"></span></a>\'+
                                \'</div>\'+
                                \'<div class="pageCreated">\'+pageCreated+\'</div>\'+
                                \'<div class="columns">\'+Pages[i].columns+\'</div>\'+
                            \'</li>\');

                /* Setting the page data for each hyperlink: */
                pageItem.find(\'a\').data(\'page\',\'/\'+dirurlll+\'/ajax.php?action=\'+bkid+\'lists&page_id=\'+Pages[i].page_id);


                // remove the new page and settings links so they can be added back to the end
                jQuery(\'#newPageItem\').remove();

                /* Adding the tab to the UL container: */
                jQuery(\'#pageList\').append(pageItem).fadeIn(\'fast\');

                // add link to create a new page
                var newPage = jQuery(
                    \'<li id="newPageItem">\'+
                        \'<abbr title="\'+_(\'New Page\')+\'"><a href="" class="notebookIcons newPage">\'+
                        \'</a></abbr>\'+
                    \'</li>\');

                    jQuery(\'#pageList\').append(newPage);

                jQuery(\'#pageList\').append(newPage).fadeIn(\'fast\');

            });  // close $.each(Pages)
            makePagesDroppable();
        });  // close newTab ajax call
}

1 个回复
SO网友:W442

这就是我在stackexchange上发帖的原因。我花了一个月的时间研究这个问题,然后我一发布这个问题就找到了解决方案(多亏了米洛也证实了我的怀疑)。

解决方案是,自由职业者编写的脚本试图调用完整的URL,并在本地主机上尝试获取文件URL。

解决方案是用插件文件的相对路径替换脚本中“DIRURL”或“DIRURLL”的所有实例。我使用记事本++进行了“在文件中查找”搜索,找到了肇事者,然后用相对路径替换了所有内容——插件立即开始工作(当然是在刷新之后)。

谢谢各位。

结束

相关推荐

自定义php文件的jQuery AJAX:返回空数据

我创建了一个自定义php文件,将其放在我的文件夹中。这些文件将一些数据插入到我创建的自定义表的数据库中。require wp_path() . \"/wp-load.php\"; global $wpdb; $favorite_table = $wpdb->prefix . \"fav\"; $wpdb->insert( $favorite_table, array( \'link\' => $_POST[\'fav_link\'], \'title\'=>