Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Ajax网页在重定向后未显示最新内容_Javascript_Php_Jquery_Ajax - Fatal编程技术网

Javascript Ajax网页在重定向后未显示最新内容

Javascript Ajax网页在重定向后未显示最新内容,javascript,php,jquery,ajax,Javascript,Php,Jquery,Ajax,我有一个页面可以显示来自不同目录的图像,并且可以根据jQuery可排序列表中文件的顺序更改文件夹中文件的文件名 到目前为止,除了保存新文件名和保存页面重定向到编辑页面后,我必须执行“空缓存和硬重新加载”以显示新文件顺序外,所有操作都正常 编辑页面 <!DOCTYPE html> <?php session_start(); if (!$_SESSION['username']) { echo "<script>window.location = './ind

我有一个页面可以显示来自不同目录的图像,并且可以根据jQuery可排序列表中文件的顺序更改文件夹中文件的文件名

到目前为止,除了保存新文件名和保存页面重定向到编辑页面后,我必须执行“空缓存和硬重新加载”以显示新文件顺序外,所有操作都正常

编辑页面

<!DOCTYPE html>
<?php
session_start();
if (!$_SESSION['username']) {
    echo "<script>window.location = './index.php'</script>";
}
?>
<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="Cache-control" content="no-cache">
        <meta http-equiv="Expires" content="-1">
        <link rel="stylesheet" href="../js/jquery/jquery-ui-1.11.4/jquery-ui.css">
        <script src="../js/jquery/jquery-2.1.4.min.js"></script>
        <script src="../js/jquery/jquery-ui-1.11.4/jquery-ui.js"></script>
        <script>
            $(window).load(function() {
                $(document).ready(function() {
                    $("#btnRefresh").click(function() {
                        window.location.reload(true);
                    });
                    $.ajax({
                        url: 'getPics.php',
                        success: function(resultOfAjaxCall) {
                            xmlDoc = $.parseXML(resultOfAjaxCall);
                            $xml = $(xmlDoc);
                            html = "";
                            $xml.find('Folder').each(function(index) {
                                //console.log($(this).attr('Name'));
                                city = $(this).attr('Name');
                                html += "<h3 class='accordion-header'>" + city + "</h3>";
                                html += "<div class='accordion-section'>";
                                html += "<button id='" + city + "_Save'>Save " + city + "</button>";
                                html += "    ";
                                //Upload Form
                                html += '<form enctype="multipart/form-data" action="uploader.php" method="POST">';
                                html += '<input type="hidden" name="MAX_FILE_SIZE" value="100000" />';
                                html += '<input type="hidden" name="City_Folder" value="' + city + '" />';
                                html += 'Choose a file to upload: <input name="userfile" type="file" /><br />';
                                html += '<input type="submit" value="Upload File" />';
                                html += '</form>';
                                //Save Form
                                html += '<form enctype="multipart/form-data" action="save.php" method="POST" id="' + city + '_Save_Form">';
                                html += '<input type="hidden" name="City_Folder" value="' + city + '" />';
                                html += '</form>';
                                html += "<ul class='" + city + "-sortable-list'>";
                                $(this).find('File').each(function(index) {
                                    //console.log($(this).text()
                                    fileName = $(this).find('File_Name').text();
                                    filePath = $(this).find('File_Path').text();
                                    fileRealPath = $(this).find('File_Real_Path').text();
                                    //console.log(fileName);
                                    //console.log(filePath);
                                    html += '<form enctype="multipart/form-data" action="delete.php" method="POST" id="' + fileName + '_Delete_Form">';
                                    html += '<input type="hidden" name="Delete_Path" value="' + filePath + '" />';
                                    html += '</form>'
                                    html += "<li id='" + fileName + "' class='ui-state-default' value='" + fileRealPath + "'>" + fileName + "    ";
                                    html += "<button id='" + fileName + "_Delete'>Delete</button>";
                                    html += "<br>"
                                    html += "<img src='" + filePath + "' style='width:150px;'/>";
                                    html += "<br></li>";
                                })
                                html += "</ul>";
                                html += "</div>";
                                //window.location.reload(true);
                            });
                            $("#accordion").append(html);
                            var $accordion = $("#accordion").accordion({
                                collapsible: true,
                                heightStyle: "content",
                                active: false
                            });
                            $("[class$=-sortable-list]").sortable({
                                update: function(event, ui) {
                                    console.log(ui);
                                    var order = [];
                                    $("[class$=-sortable-list] li").each(function(e) {
                                        order.push($(this).attr("id") + "=" + ($(this).index() + 1));
                                    });
                                    var positions = order.join();
                                    //        alert(positions);
                                },
                                stop: function(event, ui) {
                                    console.log("an item was moved");
                                    $accordion.find("#tmp").remove();
                                },
                                start: function(event, ui) {
                                    $accordion.append("<ul id='tmp'></ul>");
                                            $accordion.find("#tmp").append(ui.item);
                                }
                            }).disableSelection();


                            //Save Click   
                            $("[id$=_Save_Form]").submit(function(event) {
                                folder = event.target.id.replace("_Save_Form", "");
                                $("." + folder + "-sortable-list li").each(function(e) {
                                    //alert(folder);
                                    //alert($(this).index());
                                    //alert($(this).attr("value"));
                                    $("<input />").attr("type", "hidden")
                                            .attr("name", "path[" + $(this).index() + "]")
                                            .attr("value", $(this).attr("value"))
                                            .appendTo("#" + event.target.id);
                                });

                            });
                            $("[id$=_Save]").click(function(event) {
                                $("#" + event.target.id + "_Form").submit();
                            });
                        }
                    });
                });
            });
        </script>
        <title>Edit Slider</title>
    </head>
    <body>
        <?php ?>
        <p>You are logged in as <?= $_SESSION['username'] ?> (<a href="./index.php?logout=1">Logout</a>)</p>
        <p><button id="btnRefresh">Refresh</button></p>

        <div id="accordion">

        </div>
    </body>
</html>

()

刷新

保存页

<?php
$root = filter_input(INPUT_SERVER, "DOCUMENT_ROOT", FILTER_SANITIZE_STRING, FILTER_SANITIZE_MAGIC_QUOTES);
require $root . '/CC_Library/CC_Folder.php';
require $root . '/CC_Library/CC_String.php';
$folder = filter_input(INPUT_POST, "City_Folder", FILTER_SANITIZE_STRING, FILTER_SANITIZE_MAGIC_QUOTES);
$dir = "";
$i = 0;
$s = new CC_String;
$tmp = $s->generate_rand(5);
foreach ($_POST['path'] as $value) {
    $CC = new CC_File($value);
    $dir = $CC->get_File_Dir();

    echo "Changing " . $CC->get_Full_File_Name() . " to " . $tmp . str_pad($i, 10, '0', STR_PAD_LEFT) . "." . $CC->get_File_Extension() . "<br>";
    $CC->Rename($tmp . str_pad($i, 10, '0', STR_PAD_LEFT) . "." . $CC->get_File_Extension());
    $i++;
}
$j = 0;
//echo $dir;
$F = new CC_Folder($dir);
$Files = $F->get_Folder_Files();
foreach ($Files as $value) {
    echo "Changing " . $value->get_Full_File_Name() . " to " . $folder . "-" . str_pad($j, 8, '0', STR_PAD_LEFT) . "." . $value->get_File_Extension() . "<br>";
    $value->Rename($folder . "-" . str_pad($j, 8, '0', STR_PAD_LEFT) . "." . $value->get_File_Extension());
    $j++;
}
echo "<script>window.location.replace('Edit_Slider.php')</script>";

我不想读那些臭名昭著的代码。您的问题是客户端的,而不是服务器端的,因此您的代码是不相关的。
您的webbrowser正在缓存而不是更新您的图像。解决此问题的方法是使用如下时间戳扩展当前图像源:

<img src="image.jpg?lastmod=12345678"

之所以这样做,是因为源URL每次都不同,因为时间戳总是不同的&web浏览器会记住与URL相关的内容

function(img_src){
     var timestamp = (new Date()).getTime();
     img_src += "lastmod?" + timestamp;
}