使用ASP .NET的ExtJs 5 Ajax请求(ExtJs 5 Ajax Request with ASP .NET)

编程入门 行业动态 更新时间:2024-10-24 06:34:04
使用ASP .NET的ExtJs 5 Ajax请求(ExtJs 5 Ajax Request with ASP .NET)

尽管我付出了最大的努力,但我无法将带有Json数据的Ajax请求发送到远程Web服务器。 我不知道我能用什么其他地方启用CORS并且我的想法已经用完了。

Azure网站应用程序设置:

cors:allowOrigins: *

MVC控制器:我安装了NuGet Cors软件包

[EnableCors(origins: "*", headers: "*", methods: "*")]

Web.config文件:

<httpProtocol> <customHeaders> <clear /> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol>

ExtJs Ajax请求:

Ext.Ajax.request({ url: app.utilities.url, defaultHeaders: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, Authorization,Content-Length, X-Requested-With' }, cors: true, useDefaultXhrHeader: false, params: { jsonData: Ext.util.JSON.encode(formData) }

但我仍然得到:跨源请求被阻止:同源策略不允许在{my url}读取远程资源这可以通过将资源移动到同一域或启用CORS来解决。

有什么我想念的吗?

Despite my best efforts I am not able to send an Ajax request with Json data to a remote web server. I do not know what other places I can put enable CORS and am running out of ideas.

Azure Website App Settings:

cors:allowOrigins: *

MVC Controller: I had installed the NuGet Cors package

[EnableCors(origins: "*", headers: "*", methods: "*")]

Web.config:

<httpProtocol> <customHeaders> <clear /> <add name="Access-Control-Allow-Origin" value="*" /> </customHeaders> </httpProtocol>

ExtJs Ajax Request:

Ext.Ajax.request({ url: app.utilities.url, defaultHeaders: { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Methods': 'GET,PUT,POST,DELETE,OPTIONS', 'Access-Control-Allow-Headers': 'Content-Type, Authorization,Content-Length, X-Requested-With' }, cors: true, useDefaultXhrHeader: false, params: { jsonData: Ext.util.JSON.encode(formData) }

Yet I still get: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at {my url} This can be fixed by moving the resource to the same domain or enabling CORS.

Is there something I am missing?

最满意答案

你会考虑JsonP(带填充的JSON)吗?

http://docs.sencha.com/extjs/6.0/6.0.0-classic/#!/api/Ext.data.JsonP

Would you consider JsonP (JSON with Padding)?

http://docs.sencha.com/extjs/6.0/6.0.0-classic/#!/api/Ext.data.JsonP

更多推荐

CORS,url,Ajax,cors,电脑培训,计算机培训,IT培训"/> <meta name="descriptio

本文发布于:2023-07-25 19:43:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1265221.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NET   ASP   ExtJs   Request   Ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!