我需要POST时使用GET的window.location.href [英] window.location.href using GET when I need POST

查看:52
本文介绍了我需要POST时使用GET的window.location.href的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下脚本,从底部开始几行,我有一个 window.location.href ,它通过地址栏发布了表单中的结果.这非常混乱,我想使用POST而不是GET,任何想法都可以吗?

I have the following script, a few lines up from the bottom I have a window.location.href which posts the reults from my form though the address bar. This is very messy and I would like to use POST instead of GET, any ideas anyone ?

<script language="javascript">
function OnChangedUsername()
{
  if(document.signup.newuserid.value == "")
  {
    document.signup.btnCheckAvailability.disabled = true;
  }
  else
  {
    document.signup.btnCheckAvailability.disabled = false;
  }
}
function createRequestObject() {
  var ro;
  var browser = navigator.appName;
  if(browser == "Microsoft Internet Explorer"){
    ro = new ActiveXObject("Microsoft.XMLHTTP");
  }else{
    ro = new XMLHttpRequest();
  }
  return ro;
}

var http = createRequestObject();

function sndReq() {
  http.open('get', 'password_check.asp?emailaddress=<%Response.Write(emailaddress)%>&check=<%Response.Write(check)%>&password_check='+document.signup.newuserid.value);
  http.onreadystatechange = handleResponse;
  http.send(null);
}

function handleResponse() {
  if(http.readyState == 4){
    var response = http.responseText;
    var update = new Array();

    if(response.indexOf('|' != -1)) {
      update = response.split('|');
      document.getElementById("username_chk").innerHTML = update[0];


      if(document.getElementById("username_chk").innerHTML == "Ok") {
        window.location.href='detailsupdate.asp?username=<%Response.Write(sUsername)%>&check=<%Response.Write(check)%>&EmailAddress='+document.signup.EmailAddress.value+'&Address='+document.signup.Address.value+'&Address1='+document.signup.Address1.value+'&Address2='+document.signup.Address2.value+'&City='+document.signup.City.value+'&PostalCode='+document.signup.PostalCode.value+'&Country='+document.signup.Country.value+'&WorkPhone='+document.signup.WorkPhone.value+'&HomePhone='+document.signup.HomePhone.value+'&MobilePhone='+document.signup.MobilePhone.value+'&FaxNumber='+document.signup.FaxNumber.value+'&AlternativePhone='+document.signup.AlternativePhone.value+'&OO='+document.signup.OO.checked+'&Workshop='+document.signup.Workshop.checked+'&Raised='+document.signup.Raised.checked+'&Ground='+document.signup.Ground.checked+'&pd='+document.signup.newuserid.value+'&Tram='+document.signup.Tram.checked;
      }
    }
  }
}
</script>

推荐答案

无需将表单数据作为GET数据传递.您可以将方法指定为POST.

There is no need to pass form data as GET data. You can specify the method as POST.

<form action="script.asp" method="post">
   ...
   <input type="submit" value="submit">
</form>

您也不应该使用 window.location.href .这很丑.提交表单时(单击提交"按钮),它将把表单数据发布到script.asp.

You also should not be using window.location.href. This is very ugly. When you submit the form (click the submit button) it will POST your form data to script.asp.

提交表单的另一种方法是通过DOM提交表单. document.forms [0] .submit();

Another way to submit your form is to submit it via DOM. document.forms[0].submit();

这篇关于我需要POST时使用GET的window.location.href的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆