Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 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?

question from:https://stackoverflow.com/questions/65834357/jsjquery-and-php-etag-didnt-work-on-apache

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...