0

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

我的问题是fileloc。我无法让我的 ajax 调用发布 fileloc 并保持 dir 结构完整。我已经尝试了 escape()、encodeURI()、encodeURIComponent() 和 JQuery 的这些函数的版本。无论如何,我的 fileloc 在 saveConfigTemplates.php 页面上显示为:“D:TestPHPconfigurationautomationtemplatesservernamefilename.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);

             }
            });

        }
4

1 回答 1

2

转义反斜杠:

var fileloc = "D:\\TestPHP\\configuration\\automation\\templates\\servername\\filename.cfg";
于 2012-08-31T14:45:26.570 回答