/***************************************************************
* *
* 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
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-Origin
head 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