Trouble on checking of image existing on remote server in Chrome browser by using XMLHttpRequestChecking if a key exists in a JavaScript object?XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-OriginCheck if element exists in jQueryJavaScript check if variable exists (is defined/initialized)AngularJS performs an OPTIONS HTTP request for a cross-origin resourceWhy does my JavaScript code get a “No 'Access-Control-Allow-Origin' header is present on the requested resource” error when Postman does not?Font from origin has been blocked from loading by Cross-Origin Resource Sharing policyXMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' headerResponse to preflight request doesn't pass access control checkNo 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API

What officially disallows US presidents from driving?

Is a suit against a Univeristy Dorm for changing policies on a whim likely to succeed (USA)?

Type leftwards arrow on macOS

How do I get rid of distorted pictures of distant objects photographed with a telephoto lens?

Modify width of first column in file with a variable number of fields, using awk

What are the durations of strokes and events in a 4-stroke engine?

Leaving out pronouns in informal conversation

Why isn't `typename` required for a base class that is a nested type?

Where does the expression "triple-A" come from?

What is a realistic time needed to get a properly trained army?

How can I discourage sharing internal API keys within a company?

Napkin Folding Problem / Rumpled Ruble Problem

A medieval fantasy adventurer lights a torch in a 100% pure oxygen room. What happens?

What are uses of the byte after BRK instruction on 6502?

Will replacing a fake visa with a different fake visa cause me problems when applying for a legal study permit?

Maintenance tips to prolong engine lifespan for short trips

Is English tonal for some words, like "permit"?

Square roots and cube roots equation

Evidence that matrix multiplication cannot be done in O(n^2 poly(log(n))) time

Why is the Digital 0 not 0V in computer systems?

Telling my mother that I have anorexia without panicking her

What does 1500万0000円 mean on a price display?

Why is Kirchoff's loop rule true in a DC circuit?

Confirm the ending of a string



Trouble on checking of image existing on remote server in Chrome browser by using XMLHttpRequest


Checking if a key exists in a JavaScript object?XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-OriginCheck if element exists in jQueryJavaScript check if variable exists (is defined/initialized)AngularJS performs an OPTIONS HTTP request for a cross-origin resourceWhy does my JavaScript code get a “No 'Access-Control-Allow-Origin' header is present on the requested resource” error when Postman does not?Font from origin has been blocked from loading by Cross-Origin Resource Sharing policyXMLHttpRequest cannot load XXX No 'Access-Control-Allow-Origin' headerResponse to preflight request doesn't pass access control checkNo 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-1















I use this JQuery method on page to check if image exists:



function imageExists(imageUrl) 
var http = new XMLHttpRequest();
http.open('HEAD', imageUrl, false);
http.send();
return http.status !== 404;



If I load the page in browser, it works great, but if I go to the next page and then go back to this page the script does not work correctly. There is error in browser console:




Access to XMLHttpRequest at 'https://server/image.jpg' from origin 'http://client' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.




This error occurs only when I back from another site page to this page in Chrome browser. There is no error in Firefox and Edge browsers



Thanks!!!










share|improve this question





















  • 1





    That error should be there in either case, CORS does not depend on whether you navigate back and forth between your own pages, but solely on whether the remote host allows this kind of request, or not.

    – 04FS
    Mar 27 at 12:06











  • I know and CORS is enabled on Server with images. Maybe CORS policy is set not correctly on remote server. But why it works without errors on loading page?

    – Hennadii Feshchuk
    Mar 27 at 12:09







  • 1





    Then the response should show the appropriate headers in the network panel; does it?

    – 04FS
    Mar 27 at 12:11


















-1















I use this JQuery method on page to check if image exists:



function imageExists(imageUrl) 
var http = new XMLHttpRequest();
http.open('HEAD', imageUrl, false);
http.send();
return http.status !== 404;



If I load the page in browser, it works great, but if I go to the next page and then go back to this page the script does not work correctly. There is error in browser console:




Access to XMLHttpRequest at 'https://server/image.jpg' from origin 'http://client' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.




This error occurs only when I back from another site page to this page in Chrome browser. There is no error in Firefox and Edge browsers



Thanks!!!










share|improve this question





















  • 1





    That error should be there in either case, CORS does not depend on whether you navigate back and forth between your own pages, but solely on whether the remote host allows this kind of request, or not.

    – 04FS
    Mar 27 at 12:06











  • I know and CORS is enabled on Server with images. Maybe CORS policy is set not correctly on remote server. But why it works without errors on loading page?

    – Hennadii Feshchuk
    Mar 27 at 12:09







  • 1





    Then the response should show the appropriate headers in the network panel; does it?

    – 04FS
    Mar 27 at 12:11














-1












-1








-1








I use this JQuery method on page to check if image exists:



function imageExists(imageUrl) 
var http = new XMLHttpRequest();
http.open('HEAD', imageUrl, false);
http.send();
return http.status !== 404;



If I load the page in browser, it works great, but if I go to the next page and then go back to this page the script does not work correctly. There is error in browser console:




Access to XMLHttpRequest at 'https://server/image.jpg' from origin 'http://client' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.




This error occurs only when I back from another site page to this page in Chrome browser. There is no error in Firefox and Edge browsers



Thanks!!!










share|improve this question
















I use this JQuery method on page to check if image exists:



function imageExists(imageUrl) 
var http = new XMLHttpRequest();
http.open('HEAD', imageUrl, false);
http.send();
return http.status !== 404;



If I load the page in browser, it works great, but if I go to the next page and then go back to this page the script does not work correctly. There is error in browser console:




Access to XMLHttpRequest at 'https://server/image.jpg' from origin 'http://client' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.




This error occurs only when I back from another site page to this page in Chrome browser. There is no error in Firefox and Edge browsers



Thanks!!!







javascript jquery cors xmlhttprequest






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 10:08







Hennadii Feshchuk

















asked Mar 27 at 11:57









Hennadii FeshchukHennadii Feshchuk

599 bronze badges




599 bronze badges










  • 1





    That error should be there in either case, CORS does not depend on whether you navigate back and forth between your own pages, but solely on whether the remote host allows this kind of request, or not.

    – 04FS
    Mar 27 at 12:06











  • I know and CORS is enabled on Server with images. Maybe CORS policy is set not correctly on remote server. But why it works without errors on loading page?

    – Hennadii Feshchuk
    Mar 27 at 12:09







  • 1





    Then the response should show the appropriate headers in the network panel; does it?

    – 04FS
    Mar 27 at 12:11













  • 1





    That error should be there in either case, CORS does not depend on whether you navigate back and forth between your own pages, but solely on whether the remote host allows this kind of request, or not.

    – 04FS
    Mar 27 at 12:06











  • I know and CORS is enabled on Server with images. Maybe CORS policy is set not correctly on remote server. But why it works without errors on loading page?

    – Hennadii Feshchuk
    Mar 27 at 12:09







  • 1





    Then the response should show the appropriate headers in the network panel; does it?

    – 04FS
    Mar 27 at 12:11








1




1





That error should be there in either case, CORS does not depend on whether you navigate back and forth between your own pages, but solely on whether the remote host allows this kind of request, or not.

– 04FS
Mar 27 at 12:06





That error should be there in either case, CORS does not depend on whether you navigate back and forth between your own pages, but solely on whether the remote host allows this kind of request, or not.

– 04FS
Mar 27 at 12:06













I know and CORS is enabled on Server with images. Maybe CORS policy is set not correctly on remote server. But why it works without errors on loading page?

– Hennadii Feshchuk
Mar 27 at 12:09






I know and CORS is enabled on Server with images. Maybe CORS policy is set not correctly on remote server. But why it works without errors on loading page?

– Hennadii Feshchuk
Mar 27 at 12:09





1




1





Then the response should show the appropriate headers in the network panel; does it?

– 04FS
Mar 27 at 12:11






Then the response should show the appropriate headers in the network panel; does it?

– 04FS
Mar 27 at 12:11













1 Answer
1






active

oldest

votes


















0
















This issue has been fixed by adding request header of 'Cache-Control' with 'no-cache' value:



function imageExists(imageUrl) 
var http = new XMLHttpRequest();

http.open('HEAD', imageUrl, false);
http.setRequestHeader('Cache-Control', 'no-cache');
http.send();

return http.status !== 404;






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55376644%2ftrouble-on-checking-of-image-existing-on-remote-server-in-chrome-browser-by-usin%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0
















    This issue has been fixed by adding request header of 'Cache-Control' with 'no-cache' value:



    function imageExists(imageUrl) 
    var http = new XMLHttpRequest();

    http.open('HEAD', imageUrl, false);
    http.setRequestHeader('Cache-Control', 'no-cache');
    http.send();

    return http.status !== 404;






    share|improve this answer





























      0
















      This issue has been fixed by adding request header of 'Cache-Control' with 'no-cache' value:



      function imageExists(imageUrl) 
      var http = new XMLHttpRequest();

      http.open('HEAD', imageUrl, false);
      http.setRequestHeader('Cache-Control', 'no-cache');
      http.send();

      return http.status !== 404;






      share|improve this answer



























        0














        0










        0









        This issue has been fixed by adding request header of 'Cache-Control' with 'no-cache' value:



        function imageExists(imageUrl) 
        var http = new XMLHttpRequest();

        http.open('HEAD', imageUrl, false);
        http.setRequestHeader('Cache-Control', 'no-cache');
        http.send();

        return http.status !== 404;






        share|improve this answer













        This issue has been fixed by adding request header of 'Cache-Control' with 'no-cache' value:



        function imageExists(imageUrl) 
        var http = new XMLHttpRequest();

        http.open('HEAD', imageUrl, false);
        http.setRequestHeader('Cache-Control', 'no-cache');
        http.send();

        return http.status !== 404;







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 28 at 10:06









        Hennadii FeshchukHennadii Feshchuk

        599 bronze badges




        599 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55376644%2ftrouble-on-checking-of-image-existing-on-remote-server-in-chrome-browser-by-usin%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript