我正在尝试对GroupMe API进行API调用以获取
JSON响应,但一直收到以下错误:
XMLHttpRequest cannot load ...(call url)... Request header field X-CSRFToken is not allowed by Access-Control-Allow-Headers in preflight response.
我的Javascript看起来像这样:
var xmlhttp = new XMLHttpRequest(); var url = (call url) xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { xmlhttp.open("GET",url,true); xmlhttp.setRequestHeader("Access-Control-Allow-Headers","*"); xmlhttp.setRequestHeader('Access-Control-Allow-Origin','*'); $.getJSON(url,function(data){ var array = data.response.messages.reverse(); for(i = 0; i<array.length; i++){ $('.messages').append("<div class='message'>"+array[i].name+":<br>"+array[i].text+"</div>"); } }); } } xmlhttp.open("GET",true); xmlhttp.send();