Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https

0
$(document).ready(function(){
    $.ajax({
        url: 'https://swapi.co/api/people/1/?format=json',
        type:'GET',
        dataType: 'JSON',
        success: function(json){
            console.log(json.name);
            $("h2.name").text(json.name);
        }
    });

    const ITERACIONES_1=6;
    const ITERACIONES_2=3;
    let helper= {
      film:'',
      counter:0,
      method: function (per,res) {
        this.film += res.title;
        this.counter++;
        if (this.counter == (ITERACIONES_1 * ITERACIONES_2)) {
          for (var index = 0; index < ITERACIONES_1; index++) {
            var a = $("<div data-toggle='modal' data-target='#myModal'" + 
            "onclick=\"data2('"+this.film+"')\" class='col-md-4'>" +
          per.results[index].name + "</div>");
          $(".row").append(a);
          console.log(per.results[index].name);
          }
          $(".btnNext").attr("id", per.next);
        }
      }
    };

    $.ajax({
            url: 'https://swapi.co/api/people/?format=json',
            type:'GET',
            dataType: 'JSON',
            success: function(per){
                $(".row").empty();
                var film;
                for (var i = 0; i < ITERACIONES_1; i++) {
                    for (var index = 0; index < ITERACIONES_2; index++) {
                        var ul = per.results[i].films[index];
                        $.ajax({
                            url:ul,
                            type: 'GET',
                            dataType: 'JSON',
                            success:function(res){
                                helper.method(per,res);
                            }
                        }); 
                    } 
                }
            }
        });

        $(".btnNext").click(function(){
            var a = $(".btnNext").attr("id");
            $.ajax({
                url: a,
                type:'GET',
                dataType: 'JSON',
                success: function(per){
                    var film;
                    for (var i = 0; i < ITERACIONES_1; i++) {
                        for (var index = 0; index < ITERACIONES_2; index++) {
                            var ul = per.results[i].films[index];
                            $.ajax({
                                url:ul,
                                type: 'GET',
                                dataType: 'JSON',
                                success:function(res){
                                    helper.method(per,res);
                                }
                            }); 
                        } 
                    }
                }
            });

        });




});

function data2(nom){
    //alert(nom);
    $(".modal-body > p").remove();
    $(".modal-body").append("<p>"+nom+"</p>");  
}

when executing the click event, this error marks me

  

jquery.min.js: 4 Failed to load   file: /// C: /Users/Emma/Desktop/test/starwars.html#: Cross origin   requests are only supported for protocol schemes: http, data, chrome,   chrome-extension, https.

    
asked by Ernesto Emmanuel Yah Lopez 17.10.2017 в 19:14
source

1 answer

1

In principle, what you are saying is that you are trying to access files that are on an "external" server.

On one page I read a couple of ways to "skip" that restriction, I put it here and you take a look.

Open local page with Ajax

In it he talks about two ways of doing it, which are:

  • Close all Chrome pages (if not, it does not work), open the command console, and write this path, which in the case of Windows is "C: \ Program Files (x86) \ Google \ Chrome \ Application \ chrome.exe "--allow-file-access-from-files . According to the version of Windows that you have, you will have to remove the (x86) of the name. Once this is done, you can execute it. When you close the window, you must repeat the steps again.

  • Use Internet Explorer (not recommended).

I hope it works for you.

    
answered by 24.04.2018 в 16:52