locked
How to write debugging information out to the browser's console RRS feed

  • Question

  • User1913162092 posted

    From a .asp file and VBscript, how can I write debugging information out to the browser's console?

    Friday, January 18, 2019 10:30 PM

All replies

  • User475983607 posted

    From a .asp file and VBscript, how can I write debugging information out to the browser's console?

    Write JavaScript to the response.

        <%
            Dim myVar
            myVar = "Hello World"
            Response.Write "<script>console.log('" & myVar & "')</script>"
        %>

    Friday, January 18, 2019 11:02 PM
  • User1913162092 posted

    WONDERFUL!  Your solution works like a charm.  Thanks !!!

    Friday, January 18, 2019 11:09 PM
  • User1913162092 posted

    I was excited to see a response that, at the time, seemed to be exactly what I need.

    However, the outputs generated by the console.log method do not seem to survive any subsequent RESPONSE.REDIRECT statements.  My specific need was to be able to write to the console as my web site is running.  To do that my debugging text needs to survive across redirection to another page.

    Here's a snippet of source:

    myString = "Assign1.asp?IHSAID=" & Request("IHSAID") & "&mode=" & Session("Assignments")
    Response.Write "<script>console.log('" & myString & "')</script>"
    'response.end

    In the above case I do not see anything on the console.  However, if I remove the comment from the last line it works.

    Thoughts?

    Friday, January 18, 2019 11:40 PM
  • User475983607 posted

    joethall

    I was excited to see a response that, at the time, seemed to be exactly what I need.

    However, the outputs generated by the console.log method do not seem to survive any subsequent RESPONSE.REDIRECT statements.  My specific need was to be able to write to the console as my web site is running.  To do that my debugging text needs to survive across redirection to another page.

    Here's a snippet of source:

    myString = "Assign1.asp?IHSAID=" & Request("IHSAID") & "&mode=" & Session("Assignments")
    Response.Write "<script>console.log('" & myString & "')</script>"
    'response.end

    In the above case I do not see anything on the console.  However, if I remove the comment from the last line it works.

    Thoughts?

    Of course, a redirect (302) response does not contain HTML.  The 302 tells the browser to do an HTTP GET to another page.

    JavaScript is loaded in the browser like a mini application therefore the script element must exist in the HTML returned from the server.  This is simply how web sites and browsers work. 

    ASP has state management feature for persisting state across HTTP GET and POSTs; Session, querystring, form fields, and cookies.  You can use a querystring to pass the data in the redirect then write the querystring values to the console.

    Saturday, January 19, 2019 12:03 AM
  • User753101303 posted

    Hi,

    You should have also a "preserve log" setting so that you can see the console log for the current http request or keep the output. Also it is better suited for tracing client side code (ie JavaScript).

    For server side code you could use the server side Console (shows in the VS output window).

    Not sure if still using ASP with VBScript (rather than ASP.NET with VB.NET or C#) but unless you maintain an old application you should consider a switch.

    Sunday, January 20, 2019 2:23 PM