寫如下代碼: request = new XMLHttpRequest(); request.open('GET', url, true); request.onreadystatechange = function() { if (request.status >= 200 && request.status < 400){ // Success! data = JSON.parse(request.responseText); console.log(data); if(data.ret == 1){ window.location = data.url; } } }; request.send();發(fā)現(xiàn)會提示:XMLHttpRequest cannot load http://XXXXX.com/app.php?callback=cb. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.YYYY.com' is therefore not allowed access.如何實現(xiàn)類似getJSON的JSONP跨域呢?
如何使用原生JS實現(xiàn)類似jQuery的getJSON功能(跨域)?
冉冉說
2019-03-20 14:19:46