0

Our office team maintains and develops a Classic ASP application using VBScript

We came across a technical task that involves creating links. When the link is clicked, we want our ASP page to invoke a POST.

The POST should be indirectly invoked by the link in the ASP.

Here is the VBScript code and link in the ASP page that invokes a VBSCript Subroutine which will ultimately invoke a 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
 %>

The ultimate desired requirement is that we want the POST to be invoked, and then we want to navigate to the page called CritiqueDetailsPopup.asp

Will the above approach? Also, is the above approach a good programming practice?

crazyTech
  • 1,379
  • 3
  • 32
  • 67
  • @Freerider Ok, yes, but will the above approach work out? Also, is the above approach a good programming practice? – crazyTech May 30 '14 at 11:32
  • I'm sorry what @Freerider? The OP wants to initiate a `POST` this is a client-side task not server-side. There is too much to explain in one comment what is wrong with this code, for a start `<%=vbscript:showCritiqueDetailsInvocation( whereFrom, critiqueID, orignalCritiqueID )%>` will fail as your trying to `Response.Write` a value that isn't a string `""`. – user692942 May 30 '14 at 12:35
  • Have you actually tried running this before asking here? – user692942 May 30 '14 at 12:36

2 Answers2

0

If you are wanting to trigger a POST from your current page you can use something like this;

  <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>

Due to limited support for VBScript in browsers now (even Microsoft don't use it), this code becomes a lot easier with 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>
user692942
  • 16,398
  • 7
  • 76
  • 175
0

my method

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