老师,首页轮播图的后台接口是什么呢?

老师,首页轮播图的后台接口是什么呢?

我使用这个:​https://www.imooc.com/api/mall-webApp/index/slider接口在接收结果上会报错提示:

index.html###:1 Access to XMLHttpRequest at 'https://www.imooc.com/api/mall-webApp/index/slider' from origin 'http://127.0.0.1:5500' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

indexCarouselAjax.js:10 POST https://www.imooc.com/api/mall-webApp/index/slider net::ERR_FAILED

(anonymous) @ indexCarouselAjax.js:10

(anonymous) @ indexCarouselAjax.js:11


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

3回答
好帮手慕言 2021-05-17 13:50:35

同学你好,Content-type不是自己随意设置的,需要前后端协调,如果想拿到数据,可以使用老师提供的写法。老师这边测试是可以拿到数据的。

祝学习愉快~

好帮手慕言 2021-05-17 11:07:36

同学你好,修改成如下代码再测试下:

xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

祝学习愉快~

好帮手慕言 2021-05-16 18:08:54

同学你好,建议请求此接口:https://www.imooc.com/api/mall-wepApp/index/slider(是wepApp,而不是webApp)。

如果还是不可以,建议把代码粘贴上来,老师帮助排查,祝学习愉快~


  • 提问者 强妹妹7248924 #1

    还是不行,还是原来的错误提示

    (function(){

        var xhr=new XMLHttpRequest();

        const url='https://www.imooc.com/api/mall-wepApp/index/slider';

        xhr.onload=function(){

            if(xhr.status>=200&&xhr.status<300||xhr.status==304){

                console.log(xhr.response)

            }

        }

        xhr.open('POST',url,true);

        xhr.setRequestHeader('Content-Type','application/json');

        xhr.send();

    })()



    2021-05-16 23:13:45
  • 提问者 强妹妹7248924 #2

    还是不行还是提示原错误,

    (function(){

        var xhr=new XMLHttpRequest();

        const url='https://www.imooc.com/api/mall-wepApp/index/slider';

        xhr.onload=function(){

            if(xhr.status>=200&&xhr.status<300||xhr.status==304){

                console.log(xhr.response)

            }

        }

        xhr.open('POST',url,true);

        xhr.setRequestHeader('Content-Type','application/json');

        xhr.send();

    })()



    2021-05-16 23:14:31
  • 提问者 强妹妹7248924 #3

    改成这样就能行了,这个是因为什么原因呢?

    2021-05-17 11:45:30
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师