简体   繁体   English

X域表单POST在Internet Explorer 9中成为GET

[英]X-Domain Form POST Becomes GET in Internet Explorer 9

I'm trying to POST a form to another subdomain in my company using javascript. 我正在尝试使用javascript将表单过帐到我公司的另一个子域中。 The address is to an API that programatically generates a PDF and returns it "inline" so that instead of going to the Downloads folder it opens in a new tab. 该地址指向API,该API以编程方式生成PDF并“内联”返回PDF,因此它会转到新选项卡中,而不是转到“下载”文件夹。

This is working in all modern browsers, but it's not working in IE 9. Upon investigation, for some reasons my form is being submitted as a GET (with no body) instead of a POST. 这适用于所有现代浏览器,但不适用于IE9。经调查,由于某些原因,我的表单是以GET(没有正文)而不是POST的形式提交的。 Here's my code: 这是我的代码:

HTML : HTML

  <form id="pdfDownloadForm" style="display:none" method="POST" target="_blank">
  </form>

Javascript : Javascript

    var form = document.getElementById("pdfDownloadForm");
    form.setAttribute("action", apiUrl + "download/pdf");
    form.setAttribute("method", "POST");
    form.setAttribute("target", "_blank");

    var input = document.createElement("input");
    input.setAttribute("type", "hidden");
    input.setAttribute("name", "html");
    input.setAttribute("value", getHtmlToConvertToPdf());
    form.appendChild(input);

    form.submit();

Since I'm using jquery, I also tried $(form).trigger('submit') , just to see if it made a difference (it didn't). 由于我使用的是jquery,因此我也尝试了$(form).trigger('submit') ,只是想看看它是否$(form).trigger('submit')没有)。

Any idea why IE9 would decide to turn this into a GET? 知道为什么IE9会决定将其转换为GET吗? Is this an old cross-domain "safety" feature that I'm going to have to work around or is there just something I'm missing that will make IE9 behave the way I want? 这是我将不得不解决的旧的跨域“安全”功能,还是缺少的某些东西会使IE9表现出我想要的方式?

我认为这是由于Win 7中的IE安全性造成的,请尝试依次单击工具> Internet选项>安全性> Internet /本地>取消选中“启用保护模式”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM