JavaScript问题使重定向和张贴提示数据到URL

JavaScript problem making redirect and posting prompt data to URL

本文关键字:提示 数据 URL 张贴 问题 重定向 JavaScript      更新时间:2023-09-26

我希望采取从弹出消息提交的数据,并通过post传递到一个URL,然后将用户重定向到一个新的URL。

如果fname和email都在那里,我想把fname和email发到一个URL。

我该怎么做?

<script type="text/javascript">
$(document).ready(function() {
  $.msgbox("<p><b>Grocery Coupons Newsletter</b></p><p>Save $$$ With Coupons and Samples in your E-Mail</p>", {
    type    : "prompt",
    inputs  : [
      {type: "text",     label: "Insert your First Name:", value: "", required: true},
      {type: "text", label: "Insert your Email:", required: true}
    ],
    buttons : [
      {type: "submit", value: "OK"},
      {type: "cancel", value: "Exit"}
    ]
  }, function(fname, email) {
    if (fname) {
      
      window.location = "http://www.google.com/";
    }
  });
});
</script>

您将需要一个表单(编写HTML或通过DOM创建一个表单),将数据附加到该表单并将其submit()

你也可以:

  1. 序列化你的表单参数到重定向URL位置
  2. 将用户发送到该URL
  3. 解析GET信息服务器端
  4. 通过Location:头将用户重定向到最终目的地。

这样你就不需要在DOM中动态创建一个新表单来提交。