• Resolved T.oby

    (@toby-1)


    Hi, I would like to use the javascript jquery get function in the following simple example:

    <script type="text/javascript" src="/wp-includes/js/jquery/jquery.js"></script>
    <script type="text/javascript">
    $.get('https://www.w3schools.com/images/w3schoolscom_gray.gif').done(
      function() {
            alert("image exists");
        }).fail(function() {
            alert("image does not exist");
        })
    </script>

    I assume here that the jquery library is in ‘/wp-includes/js/jquery/jquery.js’ of the wordpress root folder which seems to be the case for my wordpress installation. However I think I am missing something because when opening the page nothing comes up.

    Thanks for any help!

    Toby

Viewing 1 replies (of 1 total)
  • Thread Starter T.oby

    (@toby-1)

    It seems WordPress loads by default the jquery library. But WordPress works in noConflict() mode where the $ operator is not available. Therefore I wrapped my code as suggested in https://codex.www.ads-software.com/Function_Reference/wp_enqueue_script#jQuery_noConflict_wrappers.

    <script>
    jQuery(document).ready(function($) {
      $.get('https://portal.3yd.de/wp-content/uploads/2014/04/guggenheim2.jpg').done(
        function() {
            alert("image exists");
        }).fail(function() {
            alert("image does not exist");
        });
    });
    </script>

    However funnily the code only works with images on my website not the w3schools website.

Viewing 1 replies (of 1 total)
  • The topic ‘use jquery get function’ is closed to new replies.