javascript - How is this cross-domain ajax request implemented?
世界只因有你
世界只因有你 2017-07-03 11:42:04
0
2
811

In a front-end plug-in, I saw that the author's demo requested the github comment interface, but the page and interface were cross-domain. He used an ajax request, but it was different from the general writing method. I don't know how to implement it. The code is as follows, please give me some analysis.

        $.ajax('https://api.github.com/repos/fex-team/xxxx/issues/81comments?per_page=100', 
            {
                headers: {
                    Accept: 'application/vnd.github.full+json'
                },
                dataType: 'json',
                success: function(data) {
                    console.log(data);
                }
        });

Generally ajax is:

$.ajax({参数...});
世界只因有你
世界只因有你

reply all(2)
刘奇

Here are two questions:

  • The cross-domain problem is because GitHub API already supports it. You can take a look at the CORS related headers returned by the OPTIONS request. See here for details

  • As for $.ajax, both request methods are supported, namely this and this

ringa_lee

jQuery.ajax(url,[settings])
url: A URL string used to contain the request.
settings:AJAX request settings. All options are optional.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template