【问题标题】:VBScript invoking a POST from a href linkVBScript 从 href 链接调用 POST
【发布时间】:2014-05-30 11:10:44
【问题描述】:

我们的办公室团队使用 VBScript 维护和开发经典 ASP 应用程序

我们遇到了一项涉及创建链接的技术任务。单击链接时,我们希望 ASP 页面调用 POST。

POST 应该由 ASP 中的链接间接调用。

这是调用 VBSCript 子例程的 ASP 页中的 VBScript 代码和链接,该子例程最终将调用 POST:

 <%dim whereFrom
 whereFrom = "RevSummary"
 dim critiqueID
 critiqueID = 389
 dim orignalCritiqueID
 orignalCritiqueID = 249
 %>


 <a href="#" onclick="<%=vbscript:showCritiqueDetailsInvocation( whereFrom, critiqueID, orignalCritiqueID )%>" class="TenPtList" target="_blank">
                            <font color="blue">
                               Critique Details
                            </font>
                            </a>

 <%
 Sub ShowCritiqueDetails(WhereFromArg, CritiqueIDArg, OrignalCritiqueIDArg )
dim DataToSend : DataToSend = "WhereFrom=" + WhereFromArg + "&CritID=" + CritiqueIDArg + "&OriginalCritID=" + OrignalCritiqueIDArg
dim servXmlHttp
dim urlOfInterest : urlOfInterest = Application("RAMSREVURL") + "CritiqueDetailsPopup.asp"
set servXmlHttp = server.Createobject("MSXML2.ServerXMLHTTP")
servXmlHttp.Open "POST", urlOfInterest ,false
servXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
servXmlHttp.send DataToSend
Set servXmlHttp = nothing
End Sub
 %>

最终期望的要求是我们希望调用 POST,然后我们希望导航到名为 CritiqueDetailsPopup.asp 的页面

请问上面的方法?另外,上述方法是一种好的编程习惯吗?

【问题讨论】:

  • @Freerider 好的,是的,但上述方法会奏效吗?另外,上述方法是一种好的编程习惯吗?
  • 对不起@Freerider? OP 想要启动 POST 这是一个客户端任务而不是服务器端。在一条评论中有太多要解释的代码有什么问题,首先&lt;%=vbscript:showCritiqueDetailsInvocation( whereFrom, critiqueID, orignalCritiqueID )%&gt; 将失败,因为您尝试Response.Write 一个不是字符串"" 的值。
  • 在问这里之前你真的试过运行这个吗?

标签: post vbscript asp-classic msxml serverxmlhttp


【解决方案1】:

如果你想从当前页面触发POST,你可以使用这样的东西;

  <a href="<%= urlOfInterest %>" onclick="SubmitLink(this, 'POST')" class="TenPtList" target="_blank">
    <font color="blue">Critique Details</font>
  </a>

  <form id="form1">
    <input type="hidden" name="value1" value="Hello World" />
  </form>

  <script type="text/vbscript">
    Function SubmitLink(Method)
      'Get reference to the object that triggered the event
      Dim Obj
      Set Obj = Window.Event.srcElement
      'Pass Method (GET or POST) and the URL to send data to.
      Dim Form
      Set Form = Document.getElementById("form1")
      Form.Method = Method
      'Pull URL from the Href attribute
      Form.Action = Obj.Location.Href
      Call Form.Submit()
      'Return false
      SubmitLink = False
    End Function
  </script>
</body>

由于现在浏览器对 VBScript 的支持有限(甚至微软都不使用它),使用 JavaScript 后这段代码变得容易多了;

  <a href="<%= urlOfInterest %>" onclick="return submitlink(this, 'POST');" class="TenPtList" target="_blank">
    <font color="blue">Critique Details</font>
  </a>

  <form id="form1">
    <input type="hidden" name="value1" value="Hello World" />
  </form>

  <script type="text/vbscript">
    function submitlink(obj, method) {
      //Pass Method (GET or POST) and the URL to send data to.
      var form = Document.getElementById("form1");
      form.method = method;
      //Pull URL from the Href attribute
      form.action = obj.location.Href;
      form.submit();
      return false;
    }
  </script>
</body>

【讨论】:

    【解决方案2】:

    我的方法

    <form  method="post" name="frm">
     <div class="formItem">
        <a href="" class="bidibidi" onclick="frm.submit();">submit</a>
    </div>
    

    【讨论】:

      猜你喜欢
      • 2012-11-28
      • 2014-01-17
      • 2014-01-22
      • 2017-11-30
      • 1970-01-01
      • 2013-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多