0

I learned JS and JQuery via "Berb Bibo Ieguda Kats - JQuery in Action". And when I try to start sample with code from this book I get this mistake:

XMLHttpRequest cannot load file:///C:/Users/julia/AppData/Local/Book/chapter2/dom.sample.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

I've found comments about this error in other posts of stackoverflow and people say that you need to use site url of file like localhost:8089/myfile.html, but I use book's author sample without any server. It's only several html files with in line JS.

This is full JS code from file:

  $(function() {

    $.get(
      'dom.sample.html', // mistake
      function(data){
        $('#sampleDOMCode pre').html(data.replace(/</g,'&lt;').replace(/>/g,'&gt;'));
      });

    $('form#selectorForm').submit(function() {
      $('#resultingElements').html('');
      var operation = $.trim($('#operationField').val());
      if (operation.length == 0) return false;
      var wrappedSet = sampleFrame.perform(operation);
      var elements = wrappedSet.elementsForDisplay();
      var labelText = elements.length + ' matching element' + (elements.length == 1 ? '' : 's') + ':';
      $('label[for=resultingElements]').html(labelText);
      $.each(elements,function(){
        $('#resultingElements').append($('<div>'+this+'</div>'));
      });
      $('#resultsPane').fadeIn('slow');
      return false;
    });

    $('#restoreButton').click(function(){
      $('#sampleFrame').attr('src','dom.sample.page.html');
      $('#resultsPane').hide();
    });

  });
julia
  • 11
  • 2

0 Answers0