new_ajax.js文件 自己封装的;
function ajax(url,fnSucc,fnFaild)
{
var oAjax =null;
if (window.XMLHttpRequest)
{
oAjax = new XMLHttpRequest();
}
else
{
oAjax = new ActiveXObject("Microsoft.XMLHTTP");
}
oAjax.open("get","url",true)
oAjax.send()
oAjax.onreadystatechange =function()
{
if(oAjax.readyState == 4)
{
if(oAjax.status == 200)
{
fnSucc(oAjax.responseText);
}
else
{
if(fnFaild)
{
fnFaild();
}
}
}
}
}
html文件:
<script src="js/new_ajax.js"></script>
<script>
ajax('http://120.25.200.96:70//jeecg-boot/caro/client/caroGiftCard/eCardInfo?cardid=84d08585d2e1b12c5c6facfca032dcd5',function(str)
{
alert(str);
},function()
{
alert('失败了')
}
);
</script>
</head>
<body>
</body>
</html>
在调试中宝了这样的一错误提示:
new_ajax.js:26 Access to XMLHttpRequest at 'file:///Users/yusunqi/Desktop/%E6%B5%8B%E8%AF%95ajax/url' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
请问怎么怎么解决?
请求跨域了。
怎么处理跨域,请自行百度
AJAX CORS
。需要前后端配合。