如何将表单数据提交到Fancybox中的外部URL?

时间:2022-11-23 21:32:20

I have a form like this;

我有这样的表格;

<form action="https://www.exampleurl.com" method="post" id="postForm">
    @Html.HiddenFor(x => x.hiddenField)
    <button type="submit" id="btnSubmit">Submit</button>
</form>

This url "https://www.exampleurl.com" only allow POST.. When I click the btnSubmit I want to show datas on fancybox (http://fancyapps.com/fancybox/) which datas return from "https://www.exampleurl.com"..

此网址“https://www.exampleurl.com”仅允许POST ..当我点击btnSubmit时,我想在fancybox上显示数据(http://fancyapps.com/fancybox/)哪个数据从“https:/”返回/www.exampleurl.com” ..

I try a lot of things and I get this error; "localhost is not allowed by Access-Control-Allow-Origin."

我尝试了很多东西而且我得到了这个错误; “Access-Control-Allow-Origin不允许使用localhost。”

1 个解决方案

#1


1  

You've got a two-part issue here:

你有一个由两部分组成的问题:

1) Since you're doing a form post, IF the form submitted correctly the user would be directed away from your site to https://www.exampleurl.com. You'd never catch the response, because the user will now be on whatever page is served by exmapleurl.com. If you'd like to be able to catch the response and keep the user on your site, you should use $.post to post data via ajax.

1)由于您正在进行表格发布,如果表单正确提交,用户将被引导离开您的网站到https://www.exampleurl.com。您永远不会收到回复,因为用户现在将在exmapleurl.com提供的任何页面上。如果您希望能够捕获响应并将用户保留在您的站点上,则应使用$ .post通过ajax发布数据。

2) Many sites will not allow cross-domain posts for security reasons, hence the Access-Control error you're getting. If you either control the destination site or are working with an administrator there, you can ask them to update the access control policy on the web server to allow posts from your domain. If you have no ability to influence the other site's policy, then you're not going to be able to do what you're attempting no matter what.

2)出于安​​全原因,许多网站不允许跨域帖子,因此您将获得访问控制错误。如果您要么控制目标站点,要么与管理员一起工作,您可以要求他们更新Web服务器上的访问控制策略以允许来自您的域的帖子。如果你没有能力影响其他网站的政策,那么无论如何你都无法做你正在尝试的事情。

#1


1  

You've got a two-part issue here:

你有一个由两部分组成的问题:

1) Since you're doing a form post, IF the form submitted correctly the user would be directed away from your site to https://www.exampleurl.com. You'd never catch the response, because the user will now be on whatever page is served by exmapleurl.com. If you'd like to be able to catch the response and keep the user on your site, you should use $.post to post data via ajax.

1)由于您正在进行表格发布,如果表单正确提交,用户将被引导离开您的网站到https://www.exampleurl.com。您永远不会收到回复,因为用户现在将在exmapleurl.com提供的任何页面上。如果您希望能够捕获响应并将用户保留在您的站点上,则应使用$ .post通过ajax发布数据。

2) Many sites will not allow cross-domain posts for security reasons, hence the Access-Control error you're getting. If you either control the destination site or are working with an administrator there, you can ask them to update the access control policy on the web server to allow posts from your domain. If you have no ability to influence the other site's policy, then you're not going to be able to do what you're attempting no matter what.

2)出于安​​全原因,许多网站不允许跨域帖子,因此您将获得访问控制错误。如果您要么控制目标站点,要么与管理员一起工作,您可以要求他们更新Web服务器上的访问控制策略以允许来自您的域的帖子。如果你没有能力影响其他网站的政策,那么无论如何你都无法做你正在尝试的事情。