Update an Asp section variable without refreshing the page

Asked

Viewed 1,300 times

0

I’m racking my brain trying to solve this problem, but to no avail...

I am with a virtual store created for another programmer who disappeared. For varying code is no documentation.

To calculate the freight in the shopping cart it calls another Asp file which in turn calls the mail webservice and returns the post value to the shopping cart. This value is then loaded into a session variable.

Freight Calculation Form within Shopping Cart:

<form method=post action=calcula_cep.asp>
<input name="met" id="met1" type="radio" value="PAC" />PAC (até 10 dias úteis)     
<input name="met" id="met2" type="radio" value="SEDEX" />SEDEX (até 4 dias úteis)
<input type=hidden name=peso value="<%=session("total_peso")%>">
<input type=text name="cep_1" id="cep_1" size=5 onkeyup="pulaCampo();" maxlength="5" class=campo value="<%=cepp1%>" readonly="readonly">-<input type=text name="cep_2" id="cep_2" size=3 maxlength="3" class=campo value="<%=cepp2%>" readonly="readonly">
<input type=submit name=submit value="Calcular" class="botao">
</form>

File calcula_cep.Asp makes the call of the mail webservice and returns the variable Value1 per post to the shopping cart:

if len(request("Valor_1")) > 0 then

   if len(session("log_cli"))>0 then
            Session("vTarifa") = Replace(request("Valor_1"),".",",")
     else
            Session("sTarifa") = replace(request("Valor_1"),".",",")
     end if

end if

What I am trying to do is an ajax request for the calcula_cep.Asp to update the value of Session("vTarifa") and Session("sTarifa"). My question is how to update the session and how to print this updated value in the cart without updating the page (by javascript?).

  • 1

    Are you sure what you want is to update a session variable? Wouldn’t it be a form field, or something on the page, to use when sent? Session variable only makes sense to keep the application status for that visitor, and when the customer is viewing the page, Asp is no longer running. Detail: with session variable, if the guy opens 2 purchase tabs and does operation on one of them, the other can be completely out of sync. You can use, but it pays to see well what will happen on the server side and what goes on the client side.

  • I’m not sure that’s the best way to do it. I am trying to adapt the cart code precisely because the customer loses the session and is dropped when calculating the freight that reloads the page. Since the code is very poorly documented, I want to change as little as possible to avoid errors in other parts of the site. The cart data is being recorded a Session() variable that is read by the checkout file. I was thinking of changing it by AJAX for when the client clicked on the checkout link it will fetch it on the server.

1 answer

2


Instead of using a Submit button, create a common button and call a function containing ajax to call this page, a Submit button will always reload it

<input type="button" onclick="calcula_cep()" value="calcular" class="botao">

Javascript

function calcula_cep() {
$.post("calcula_cep.asp",null,
     function(resposta){
       if (resposta){
          $("#controle_carrinho").html(resposta);
       }
  }
}

Vbscript

if len(request("Valor_1")) > 0 then

   if len(session("log_cli"))>0 then
        Session("vTarifa") = Replace(request("Valor_1"),".",",")
        response.write Session("vTarifa")
     else
        Session("sTarifa") = replace(request("Valor_1"),".",",")
        response.write Session("sTarifa")
     end if

end if

I hope I’ve helped

  • I had forgotten this question... I ended up doing similar to your solution, creating two new Hidden fields for shipping that are loaded by ajax and on the checkout page I load these fields in the session before loading the page...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.