Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.2k views
in Technique[技术] by (71.8m points)

JS(Jquery) and PHP Etag didnt work on Apache

I try to understand for a long time how it works.

Browser Chrome. Apache.

I create js and php code and it doesn`t work. As I understood, firt - send request with js to php, second- php add etag to header, third - after refresh js send in header If-None-Match

JS(JQuery):

$.ajax({
            async:false,
            type: "POST",
            ifModified: true,
            url: 'trackETAG.php',
            withCredentials:true,
            data: { track: true},
            success: function (data){
                newData = data;
            },
            complete: function(XMLHttpRequest, textStatus){
                var eTag = XMLHttpRequest.getAllResponseHeaders();
                var newEtag = eTag;
            }
        });

PHP:

<?php
if(!empty(isset($_POST["track"]))){
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST');
    header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Etag,  If-None-Match");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Etag: 123");


    $temp = null;
    $zte = null;
    $temp = trim($_SERVER['HTTP_IF_NONE_MATCH']);
     $zte = $temp;
}
?>

HTTP_IF_NONE_MATCH always empty.

Example

Somebody can help me?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Problem with type of request. Etag works only with GET on my program


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...