0

i have problems connecting a json file with EasyAutocomplete. My code is:

<html>
<header>
<script src="http://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="easy-autocomplete.min.js"></script>
</header>
<body>
<input id="inputOne" placeholder="X-men character" />
<input id="inputTwo" placeholder="Real name" />
</bod>
<script>
        $(document).ready(function () {
            var options = {

                url: "/neuer%20ordner/X-men.json",

                getValue: function (element) {
                    return element.character;
                },
                list: {
                    onSelectItemEvent: function () {
                        var selectedItemValue = $('#inputOne').getSelectedItemData().realName;
                        $('#inputTwo').val(selectedItemValue).trigger('change');
                    },
                    onHideListEvent: function () {
                        $('#inputTwo').val('').trigger('change');
                    }
                }
            };
            $('#inputOne').easyAutocomplete(options);
        });
</script>

My problem is, that i can#t connect to the JSON file. IF i store the data in the code:

<html>
<head>
    <script src="http://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="jquery.easy-autocomplete.min.js"></script> 
</head>
<script>
$(document).ready(function() {
                var options = {
                    data: [{'character': 'Cyclops', 'realName': 'Scott Summers'},
                        {'character': 'Professor X', 'realName': 'Charles Francis Xavier'},
                        {'character': 'Mystique', 'realName': 'Raven Darkholme'},
                        {'character': 'Magneto', 'realName': 'Max Eisenhardt'}],
                    getValue: 'character',
                    list: {
                        onSelectItemEvent: function () {
                            var value = $('#function-data').getSelectedItemData().realName;
                            $('#data-holder').val(value).trigger('change');
                        }
                    }
                };
                $('#function-data').easyAutocomplete(options);
            });
        </script>
    </script>
<body>  
<input id="function-data" />
<input id="data-holder" />
</body>
</html>

everything works fine. I have tried:

url: "http://localhost/neuer%20ordner/X-men.json", //via xampp
url: 'Neuer Ordner/neu 1/xmen.json',              //via xampp
url:'https://github.com/scherze3/test1/blob/main/X-men.json'

All don't work Can someone tell me where is my mistake. Thanks

InSync
  • 4,851
  • 4
  • 8
  • 30
  • It's probably a CORS error, you can check the Javascript console in the browser dev tools for error messages. More info on for example https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS/Errors. – Marijn Apr 15 '23 at 16:27

0 Answers0