【发布时间】:2019-01-14 08:33:59
【问题描述】:
我正在尝试将 atom 支付网关集成到我的 MVC 项目中。即使在启用 CORS 之后,我也遇到了这个令人讨厌的错误。所以我想也许是导致问题的返回网址。所以我写了一个简单的重定向来找出真正的原因return Redirect("https://google.com");,但我仍然遇到同样的错误。我做错了什么?
public ActionResult TransferFund()
{
return Redirect("https://google.com");
}
Failed to load https://google.com/: Response to preflight request doesn't pass
access control check: No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'http://localhost:25850' is therefore not allowed
access. The response had HTTP status code 405.
我已关注This 重定向
编辑
<script type="text/javascript">
$(document).ready(function () {
$('#btnatom').on('click', function () {
$.ajax({
type: 'POST',
url: "/AtomPayment/TransferFund",
data: {},
dataType: "text",
success: function (resultData) { alert("Save Complete") }
});
});
});
</script>
[HttpPost]
public ActionResult TransferFund()
{
return new RedirectResult("http://google.com");
string strURL, strClientCode, strClientCodeEncoded;
....
}
【问题讨论】:
-
@kgbph 那是怎么重复的?我确实写了同一行代码,但我收到了这个错误。
-
我可以假设您使用的是 POST(来自 js 的 ajax),而不是 GET,这就是它可能是跨域请求的原因。
-
这是一个重复的问题。也许接受的答案对您不起作用。我会尽力帮助你的。
-
@Yara TransferFund 是我通过 Jquery ajax 方法调用的 POST 方法。我刚刚发现
return Redirect("https://google.com");来自 get 操作方法,但不能从作为 post 方法的内部操作方法工作。我正在尝试从 POST 操作方法发出 GET 请求
标签: c# jquery ajax asp.net-mvc cors