煎茶ExtJS的。无法发送POST请求跨域使用Ext.Ajax.requestPOST、ExtJS、煎茶、request

2023-09-10 19:46:02 作者:浅夏丿初晴

我已经后端的与POST功能(使JSONP不工作)。 后端发送访问控制 - 允许 - 产地:* 正确(jQuery.ajax成功的作品)。 但我不能使用Ext.Ajax.request发送请求

  Ext.Ajax.request({
  网址:HTTP:// myurl,
  方法:POST,
  CORS:真正的,
  成功:函数(){
    警报(成功);
  },
  失败:函数(){
    警报(失败);
  }
});
 

在调试控制台我看到OPTIONS方法

在哪里是我的错?

  Ext.getVersion()
 

  

版本:5.0.1.1255

解决方案

我认为你必须设置 useDefaultXhrHeader 也在你的Ajax请求,如下图所示。

  Ext.Ajax.request({
  网址:HTTP:// myurl,
  方法:POST,
  CORS:真正的,
  useDefaultXhrHeader:假的,
  成功:函数(){
    警报(成功);
  },
  失败:函数(){
    警报(失败);
  }
});
 
extjs 机构管理 ajax请求失败

I have backend with POST functionality (so JSONP is not working). Backend sends Access-Control-Allow-Origin: * correctly (jQuery.ajax works successfully). But I cannot send request using Ext.Ajax.request

Ext.Ajax.request({
  url: 'http://myurl',
  method: 'POST',
  cors: true,
  success: function () {
    alert('success');
  },
  failure: function () {
    alert('failure');
  }
});

In debug console I see OPTIONS method

Where is my mistake?

Ext.getVersion()

version: "5.0.1.1255"

解决方案

I think you will have to set useDefaultXhrHeader to false also in your ajax request,like below.

Ext.Ajax.request({
  url: 'http://myurl',
  method: 'POST',
  cors: true,
  useDefaultXhrHeader : false,
  success: function () {
    alert('success');
  },
  failure: function () {
    alert('failure');
  }
});