javascript - mui develops NetEase Cloud Music, the request interface is always cross-domain
学习ing
学习ing 2017-06-12 09:29:21
0
5
970
/***************************************************************
 *                                                             *
 * mui.ajax获取数据                                                                                                                   *
 *                                                             *
/***************************************************************/
var url = 'http://s.music.163.com/search/get/';
mui.ajax(url, {
    data: {
        'type': 1,
        's': '喜欢你',
        'limit': 10
    },
    dataType: 'json',
    type: 'post',
    timeout: 10000,
    success: function(response) {
        console.log(JSON.stringify(response))
    },
    error: function(xhr, type, errorThrown) {
        console.log(type)
    }

})

When I practice using segmentfault’s mui tutorial, a cross-domain error is always reported when opening the browser. Is it because the interface cannot be used? Or is it for other reasons

学习ing
学习ing

reply all(5)
漂亮男人

I found the reason, because I opened it in a browser, which will cross domain. If I run it on a real machine, there will be no cross-domain problem

仅有的幸福

Cross-domain error means that NetEase Cloud does not allow cross-domain requests.
You need a background to forward the request

滿天的星座

I have encountered this problem before, and the reason is that NetEase does not allow cross-domain requests.

仅有的幸福

This is because the NetEase Cloud server did not return the Access-Control-Allow-Originhead field in your request, so your request was blocked by the browser.

Two solutions:

  • Order NetEase Cloud Music to allow the website you requested to cross domain, that is, let them modify the server configuration.

  • Call NetEase Cloud Music API on the backend, not through the browser.

You can also use postman for testing.

If you can bear the pain of reading in English, this article is very detailed.

给我你的怀抱

If you are just practicing, you can turn off Chrome’s restrictions on cross-domain requests, so that there will be no cross-domain problems

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!