无法在ajax调用中发布绝对文件路径-无论我做什么,它都会返回斜杠

Cannot post absolute filepath in ajax call - it drops back slashes no matter what I do

本文关键字:什么 返回 调用 ajax 文件 布绝 路径      更新时间:2023-09-26

下面是我的javascript函数,它通过post进行ajax调用。它将文件位置和文件内容发送到保存文件的php页面。其想法是,用户可以通过浏览器管理小型应用程序的配置文件模板,而不是手动登录到远程服务器,进行编辑,并将编辑提交回src控件,以拉入每个应用程序(在这个ajax调用发布数据的页面上,这一切都是自动的)。

我的问题是fileloc。我无法让我的ajax调用发布fileloc并保持dir结构的完整性。我已经尝试过escape()、encodeURI()、encodeURIComponent()和JQuery版本的这些函数。不管怎样,我的fileloc在saveConfigTemplates.php页面上显示为:"D:TestPHPConfigurationautomationtemplateservernamefilename.cfg"。我尝试过php的解码,但没有什么不同。。。这就像帖子丢失了所有编码,并将单个斜杠视为转义字符。让我抓狂的是,任何建议都很感激。

function saveFile(){
        var fileContents = $("#fileContent").val(); 
        alert(fileContents);
        var fileloc = "D:'TestPHP'configuration'automation'templates'servername'filename.cfg";
        var fileconts = "fileloc="+encodeURIComponent(fileloc)+"&fileconts="+fileContents;
            $.ajax({
            type: "POST",
            url: "saveConfigTemplates.php",
            data: fileconts,
            success: function(data) {
                alert(data);
             }
            });
        }

转义反斜杠:

var fileloc = "D:''TestPHP''configuration''automation''templates''servername''filename.cfg";