How can I execute logic code on ASP Classic Server side by using Jquery ajax?

70 views Asked by At

I try to create a simple page using ASP Classic without database and basic login I have a table with a list of cars that I can book for the user and the user can unbook the car this website should be very simple with only one user and no database

I want to execute a simple Ajax from my button that can change the book of the car I have to create the method on the table row because I have to know which car is booked

But, I can't find any way to execute a method like a Controller method that can run with $ post request

I am using the Application object as a database to save the number of cars that I can book and unbook

this post request

$.post("index.asp", function(data, status){
        console.log(data);
        console.log(status);

    });

just download the index.asp page on the data and get the Application object

Just tell me if you need more information..

this is my ASP code :

<%@ language="javascript" %>
<html>
    <head>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <meta charset="utf-8">
    </head>
    <body>
        <table align=center>
            <tr>
                <td align=center>
                    <b> LOGIN </b>
                    <br>
                    <br>
                    <br>
                    <form method=post action="index.asp" >
                        UserName <input type=text name=uname /> <br>
                        Password <input type=password name=password /> <br><br>
                        <p align=right> <input type=submit value=login name=submit /> </p>
                    </form>
                </td>
            </tr>
        </table>
    </body>
</html>

<script>

function xtt(keyName){
    $.post("index.asp", function(data, status){
        console.log(data);
        console.log(status);

    });

}
        
</script>

<%

if (typeof Application("a") === "undefined") {
Application("a") = 1;

}else{
    Application("a") = Application("a") +1;
}

Response.Write (Application("a"));


function GetCarName(sName)
{
    if((sName = "MAZDA_FOR_BOOK") || (sName = "MAZDA_FOR_USER"))
    {
        GetCarName = "מאזדה";
    }
    else if((sName = "KIA_FOR_BOOK") || (sName = "KIA_FOR_USER"))
    {
        GetCarName = "קיה";
    }
    else if((sName = "SHEV_FOR_BOOK") || (sName = "SHEV_FOR_USER"))
    {
        GetCarName = "שברולט";
    }
    else {
     GetCarName = "דייהטסו";
    }
}

  function WriteCarsTable(CarList, valueForSubmit, TestForSubmit){
    %>
            <table border='1'>
                <tr>
                    <td style='text-align: center;'> כמה רכבים </td>
                    <td style='text-align: center;'> סוג רכב </td>
                    <td style='text-align: center;'> <%TestForSubmit%></td>
                </tr>

            <%for(var i = 0; i < CarList.length; i++) {
                var key = CarList[i];%>

                <tr>
                    <td style='text-align: center;'><%=Application(key)%></td>
                    <td style='text-align: center;'><%=key%></td> 
                    <td style='text-align: center;'>
                        
                           <input name=<%=key%> type=submit value=<%=valueForSubmit%> onClick=xtt('<%=key%>')></input>
                    </td>
                <tr>
            <%}%>
            </table>
    <%
 }


%>
    <label><%=submit%></label>
<%
    var CARS_SET_FOR_BOOK = [];
    CARS_SET_FOR_BOOK.length = 4;
    CARS_SET_FOR_BOOK[1] = "MAZDA_FOR_BOOK";
    CARS_SET_FOR_BOOK[2] = "KIA_FOR_BOOK";
    CARS_SET_FOR_BOOK[3] = "SHEV_FOR_BOOK";
    CARS_SET_FOR_BOOK[4] = "DAIH_FOR_BOOK";

    var CARS_SET_FOR_USER = [];
    CARS_SET_FOR_USER.length = 4;
    CARS_SET_FOR_USER[1] = "MAZDA_FOR_USER";
    CARS_SET_FOR_USER[2] = "KIA_FOR_USER";
    CARS_SET_FOR_USER[3] = "SHEV_FOR_USER";
    CARS_SET_FOR_USER[4] = "DAIH_FOR_USER";


   if (typeof Application("init") === "undefined") 
   {
        
        Application(CARS_SET_FOR_BOOK[1]) = 1;
        Application(CARS_SET_FOR_BOOK[2]) = 2;
        Application(CARS_SET_FOR_BOOK[3]) = 3;
        Application(CARS_SET_FOR_BOOK[4]) = 4;

        Application(CARS_SET_FOR_USER[1]) = 0;
        Application(CARS_SET_FOR_USER[2]) = 0;
        Application(CARS_SET_FOR_USER[3]) = 0;
        Application(CARS_SET_FOR_USER[4]) = 0;
        Application("init") = true;
    
   }


    
    Response.Write (Request.Form);
    var res= Request.Form("uname")
    
    WriteCarsTable(CARS_SET_FOR_BOOK,"הזמן רכב","רכבים להזמנה")

    WriteCarsTable(CARS_SET_FOR_USER,"החזר רכב","רכבים שהוזמנו")

    var submit = Request.Form("submit")
    name = Request.Form("name")
    Response.Write (name)


%>
0

There are 0 answers