location.href caching and ASP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kreso

    #1

    location.href caching and ASP

    i'm passing the asp parameters using the url
    current page is files.asp
    and I'm using window.location .href=files.asp ?action=deletef ile to pass the
    action to the serverside

    My code never got executed (like the page was cached) unless i put
    document.write( "") before the window.location directive.

    Can anyone explain?



    Here's the code:


    function confirmDelete(x ){
    var potvrda=confirm ("Kliknite OK za brisanje. Cancel za povratak.");
    if (potvrda==true) {
    trans="files.as p?action="+x;
    document.write( "")
    window.location .href=trans;
    }
    else {}
    }


  • Thomas 'PointedEars' Lahn

    #2
    Re: location.href caching and ASP

    Kreso schrieb:[color=blue]
    > My code never got executed (like the page was cached)[/color]

    "Does not work" is a useless error description. [psf 4.11]
    Debug your code: <3FDBC2B2.10209 08@PointedEars. de>
    [color=blue]
    > unless i put document.write( "") before the window.location directive.[/color]

    It is an assignment statement, not a directive. Get informed about the
    programming language you are using: <http://jibbering.com/faq/#FAQ3_2>
    [color=blue]
    > [...]
    > function confirmDelete(x ){
    > var potvrda=confirm ("Kliknite OK za brisanje. Cancel za povratak.");
    > if (potvrda==true) {[/color]

    Unless you do not require potvrda's value later, you can simplify this:

    if (confirm(...))

    If you require the value later, you can still remove the "==true".
    The variable's value is already a boolean expression.
    [color=blue]
    > trans="files.as p?action="+x;[/color]

    You should use the escape() or encodeURICompon ent() methods to escape
    the value of x. See <40CEEC03.10209 09@PointedEars. de> for details.

    Besides, you are unnecessesarily defining a global variable without
    declaring it first. That is bad style. Use the "var" keyword to
    declare and define a local variable instead (var trans = ...).
    [color=blue]
    > document.write( "")[/color]

    This statement overwrites the current document. I am astonished that
    [color=blue]
    > window.location .href=trans;[/color]

    is ever executed. Surely it will not in all UAs. Remove it.
    [color=blue]
    > }
    > else {}[/color]

    An empty "else" block is nonsense. Remove it and the "else" statement.
    [color=blue]
    > }[/color]

    You should watch more for Pretty Printing, especially indentation.
    It makes your code easier legible and thus understandable.


    PointedEars

    Comment

    • Thomas 'PointedEars' Lahn

      #3
      Re: location.href caching and ASP

      Kreso schrieb:[color=blue]
      > My code never got executed (like the page was cached)[/color]

      "Does not work" is a useless error description. [psf 4.11]
      Debug your code: <3FDBC2B2.10209 08@PointedEars. de>
      [color=blue]
      > unless i put document.write( "") before the window.location directive.[/color]

      It is an assignment statement, not a directive. Get informed about the
      programming language you are using: <http://jibbering.com/faq/#FAQ3_2>
      [color=blue]
      > [...]
      > function confirmDelete(x ){
      > var potvrda=confirm ("Kliknite OK za brisanje. Cancel za povratak.");
      > if (potvrda==true) {[/color]

      Unless you do not require potvrda's value later, you can simplify this:

      if (confirm(...))

      If you require the value later, you can still remove the "==true".
      The variable's value is already a boolean expression.
      [color=blue]
      > trans="files.as p?action="+x;[/color]

      You should use the escape() or encodeURICompon ent() methods to escape
      the value of x. See <40CEEC03.10209 09@PointedEars. de> for details.

      Besides, you are unnecessarily defining a global variable without
      declaring it first. That is bad style. Use the "var" keyword to
      declare and define a local variable instead (var trans = ...).
      [color=blue]
      > document.write( "")[/color]

      This statement overwrites the current document. I am astonished that
      [color=blue]
      > window.location .href=trans;[/color]

      is ever executed. Surely it will not in all UAs. Remove it.
      [color=blue]
      > }
      > else {}[/color]

      An empty "else" block is nonsense. Remove it and the "else" statement.
      [color=blue]
      > }[/color]

      You should watch more for Pretty Printing, especially indentation.
      It makes your code easier legible and thus understandable.


      PointedEars

      Comment

      • nick

        #4
        Re: location.href caching and ASP

        look I'don't see the answer!
        My ASP code does not get executed...
        the popup window works and while it works i don't give a flying f*** about
        the sintax and proper coding

        Can you tell me why the asp code ("request("acti on")) doe not get executed
        unless i manually refresh the page or put a document.write( "") before the
        location.href

        'my damn asp code
        <%response.writ e(request("acti on"))%>
        function confirmDelete(x ){
        var potvrda=confirm ("Kliknite OK za brisanje. Cancel za povratak.");
        if (potvrda==true) {
        trans="files.as p?action="+x;
        document.write( "")
        window.location .href=trans}
        else {}
        }


        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: location.href caching and ASP

          nick schrieb:
          ^^^^
          Who?
          [color=blue]
          > look I'don't see the answer![/color]

          That's your problem.
          [color=blue]
          > My ASP code does not get executed...[/color]

          Then why you ask in a J(ava)Script/ECMAScript group?
          Ask in an ASP group.
          [color=blue]
          > the popup window works and while it works i don't give a flying f*** about
          > the sintax and proper coding[/color]

          You don't want to learn anything. Why should I give "a flying f***"
          about you(r problems)? This is not a (paid) support forum but a
          discussion group (providing free advice). Go away.


          PointedEars

          Comment

          • Lee

            #6
            Re: location.href caching and ASP

            nick said:[color=blue]
            >
            >look I'don't see the answer!
            >My ASP code does not get executed...
            >the popup window works and while it works i don't give a flying f*** about
            >the sintax and proper coding
            >
            >Can you tell me why the asp code ("request("acti on")) doe not get executed
            >unless i manually refresh the page or put a document.write( "") before the
            >location.hre f[/color]

            It probably has to do with the way that your function is being
            invoked, which you haven't shown us.

            My guess is that it's in an onclick handler of a link, and the
            current page is being reloaded when the link is followed.
            That would be because you need to learn syntax and proper coding.

            Comment

            • Kreso

              #7
              Re: location.href caching and ASP

              First of all I'm not a javascript programmer!
              Second I repeat everything i said in my last post
              Third if you don't know the solution or PLEASE do not reply to this post

              This code when saved as an *.asp file should show a link which, when
              pressed, shows a dialog which should redirect the page to itself including
              some data in the url
              the only way i got the page to reload (with the data included in the url) is
              to put document.write( "") (now commented) before the location.href=. .. (or
              to manually refresh the page)


              BEGIN CODE

              <script language="javas cript">
              <!--
              function confirmDelete(x )
              {
              if (confirm("Klikn ite OK za brisanje. Cancel za povratak.")==tr ue)
              {trans="test.as p?action=delete &nID="+x;
              //document.write( "");
              window.location .href = trans; }
              }
              //-->
              </script>
              <body>
              <%
              '//ASP CODE
              if request("action ")="delete" then response.write request("action ")
              %>
              <a href="javascrip t:;" onclick="confir mDelete(15)">[obri¹i]</a>
              </body>


              END CODE





              Comment

              • Kreso

                #8
                Re: location.href caching and ASP


                [color=blue][color=green]
                > > My ASP code does not get executed...[/color]
                >
                > Then why you ask in a J(ava)Script/ECMAScript group?
                > Ask in an ASP group.[/color]

                it is related more to javascript than asp
                [color=blue]
                >[color=green]
                > > the popup window works and while it works i don't give a flying f***[/color][/color]
                about[color=blue][color=green]
                > > the sintax and proper coding[/color]
                >
                > You don't want to learn anything. Why should I give "a flying f***"
                > about you(r problems)? This is not a (paid) support forum but a
                > discussion group (providing free advice). Go away.[/color]

                I asked for some help and all I found is you writing a smart-ass post which
                shows an increddible attitude.
                And you did not even point me in the direction of the solution - that is not
                because you don't know but because you DIDN't CARE to even try to understand
                the problem.

                Up yours MAN!


                Comment

                • Evertjan.

                  #9
                  Re: location.href caching and ASP

                  Kreso wrote on 16 jun 2004 in comp.lang.javas cript:
                  [color=blue]
                  > First of all I'm not a javascript programmer!
                  > Second I repeat everything i said in my last post
                  > Third if you don't know the solution or PLEASE do not reply to this
                  > post
                  >
                  > This code when saved as an *.asp file should show a link which, when
                  > pressed, shows a dialog which should redirect the page to itself
                  > including some data in the url
                  > the only way i got the page to reload (with the data included in the
                  > url) is to put document.write( "") (now commented) before the
                  > location.href=. .. (or to manually refresh the page)
                  >
                  >
                  > BEGIN CODE
                  >
                  > <script language="javas cript">
                  > <!--
                  > function confirmDelete(x )
                  > {
                  > if (confirm("Klikn ite OK za brisanje. Cancel za povratak.")==tr ue)
                  > {trans="test.as p?action=delete &nID="+x;
                  > //document.write( "");
                  > window.location .href = trans; }
                  >}
                  > //-->
                  > </script>
                  > <body>
                  > <%
                  > '//ASP CODE
                  > if request("action ")="delete" then response.write request("action ")
                  > %>
                  > <a href="javascrip t:;" onclick="confir mDelete(15)">[obri¹i]</a>
                  > </body>
                  >
                  >
                  > END CODE[/color]


                  change this:
                  onclick="confir mDelete(15);"
                  to:
                  onclick="confir mDelete(15);ret urn false;"

                  Otherwise it is all a question of timing which process fires first

                  =============== =============== =============== ===

                  Furthermore you could clean up your code:

                  [
                  1 Superfluous is the testing if a boolean is true,
                  the result being the same as the original boolean]
                  2 The href="javascrip t:;" will not run if javscript is not active,
                  and it will not run if it is
                  ]

                  =============== =============== =============== ====

                  <%@Language=vbs cript%>

                  <script type="text/javascript">
                  function confirmDelete(x ) {
                  if (confirm("Klikn ite OK za brisanje. Cancel za povratak."))
                  {
                  window.location .href = "test.asp?actio n=delete&nID="+ x;
                  }
                  }
                  </script>

                  <body>
                  Action:
                  <% = response.write request("action ") %>
                  <br>
                  ID:
                  <% = response.write request("ID") %>
                  <br>
                  <a href="#"
                  onclick="confir mDelete(15);ret urn false">
                  [obri¹i]</a>
                  </body>


                  --
                  Evertjan.
                  The Netherlands.
                  (Please change the x'es to dots in my emailaddress)

                  Comment

                  • Kreso

                    #10
                    Re: location.href caching and ASP

                    THANK YOU!!

                    "Evertjan." <exjxw.hannivoo rt@interxnl.net > wrote in message
                    news:Xns950AAF0 F1653Feejj99@19 4.109.133.29...[color=blue]
                    > Kreso wrote on 16 jun 2004 in comp.lang.javas cript:
                    >[color=green]
                    > > First of all I'm not a javascript programmer!
                    > > Second I repeat everything i said in my last post
                    > > Third if you don't know the solution or PLEASE do not reply to this
                    > > post
                    > >
                    > > This code when saved as an *.asp file should show a link which, when
                    > > pressed, shows a dialog which should redirect the page to itself
                    > > including some data in the url
                    > > the only way i got the page to reload (with the data included in the
                    > > url) is to put document.write( "") (now commented) before the
                    > > location.href=. .. (or to manually refresh the page)
                    > >
                    > >
                    > > BEGIN CODE
                    > >
                    > > <script language="javas cript">
                    > > <!--
                    > > function confirmDelete(x )
                    > > {
                    > > if (confirm("Klikn ite OK za brisanje. Cancel za povratak.")==tr ue)
                    > > {trans="test.as p?action=delete &nID="+x;
                    > > //document.write( "");
                    > > window.location .href = trans; }
                    > >}
                    > > //-->
                    > > </script>
                    > > <body>
                    > > <%
                    > > '//ASP CODE
                    > > if request("action ")="delete" then response.write request("action ")
                    > > %>
                    > > <a href="javascrip t:;" onclick="confir mDelete(15)">[obri¹i]</a>
                    > > </body>
                    > >
                    > >
                    > > END CODE[/color]
                    >
                    >
                    > change this:
                    > onclick="confir mDelete(15);"
                    > to:
                    > onclick="confir mDelete(15);ret urn false;"
                    >
                    > Otherwise it is all a question of timing which process fires first
                    >
                    > =============== =============== =============== ===
                    >
                    > Furthermore you could clean up your code:
                    >
                    > [
                    > 1 Superfluous is the testing if a boolean is true,
                    > the result being the same as the original boolean]
                    > 2 The href="javascrip t:;" will not run if javscript is not active,
                    > and it will not run if it is
                    > ]
                    >
                    > =============== =============== =============== ====
                    >
                    > <%@Language=vbs cript%>
                    >
                    > <script type="text/javascript">
                    > function confirmDelete(x ) {
                    > if (confirm("Klikn ite OK za brisanje. Cancel za povratak."))
                    > {
                    > window.location .href = "test.asp?actio n=delete&nID="+ x;
                    > }
                    > }
                    > </script>
                    >
                    > <body>
                    > Action:
                    > <% = response.write request("action ") %>
                    > <br>
                    > ID:
                    > <% = response.write request("ID") %>
                    > <br>
                    > <a href="#"
                    > onclick="confir mDelete(15);ret urn false">
                    > [obri¹i]</a>
                    > </body>
                    >
                    >
                    > --
                    > Evertjan.
                    > The Netherlands.
                    > (Please change the x'es to dots in my emailaddress)[/color]


                    Comment

                    Working...