为什么我的$ .ajax显示“预检是无效的重定向错误”? [英] Why my $.ajax showing "preflight is invalid redirect error"?

查看:164
本文介绍了为什么我的$ .ajax显示“预检是无效的重定向错误”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在邮递员中尝试了以下代码并且它正在运行。代码有什么问题吗?

I tried the following code in Postman and it was working. Is there something wrong with the code?

$.ajax({
   url: 'http://api.example.com/users/get',
   type: 'POST',
   headers: {
      'name-api-key':'ewf45r4435trge',
   },
   data: {
      'uid':36,
   },
   success: function(data) {
      console.log(data);
   }
});

我在控制台中收到如下错误,请告知。

I got this error in my console as below, please advise.


XMLHttpRequest无法加载 http://api.example.com/users/get 回应
预检无效(重定向)

XMLHttpRequest cannot load http://api.example.com/users/get Response for preflight is invalid (redirect)


推荐答案

我当我尝试将https网络服务称为http网络服务时收到同样的错误。

I received the same error when I tried to call https web service as http webservice.

e.g when I call url 'http://api.example.com/users/get'
which should be 'https://api.example.com/users/get'

当您尝试呼叫http而不是https时,由于重定向状态302而产生此错误。

This error is produced because of redirection status 302 when you try to call http instead of https.

这篇关于为什么我的$ .ajax显示“预检是无效的重定向错误”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆