Question

What i'm doing is depending on a link clicked, re-building the URL and reading in variables from the URL to then do an AJAX post call to a classic ASP page and subsequently insert the post values into an SQL database.

this is in the document.ready() function so that when the URL gets changed it will read in the new values;

        //check if there's a video to log, and log that video
    var params = {};
    params["loggedFrom"] = getUrlVars()["loggedFrom"];
    params["logVideo"] = getUrlVars()["logVideo"];
    params["ipAddress"] = getUrlVars()["IPAddress"];
    params["fromApp"] = "P360";
    params["fromPage"] = "P360 Trading Overview";
    params["videoName"] = getUrlVars()["videoName"];
    //alert(params["loggedFrom"]);
    if(params["logVideo"]   == "true"){
        var now = new Date();
        now = now.format("MM/dd/yyyy hh:mm:ss");

        $.ajax({
            type:"POST",
            url:"p360TradingLog.asp",
            data: params,
            success : function(d){
                alert("this post was successful");              
            }
        });
    }

params[] seems to be containing the data correctly as when doing the

alert(params["logVideo"]);

it returns the correct values, but i don't receive the "This post was successful" alert. My question is what should my code be in the p360TradingLog.asp page in order to get these posted values and insert them correctly? This is my current code but is not working correctly.

<%
        Set con = Server.CreateObject("ADODB.Connection");
        set ipAddress = Request.Form("params")("ipAddress");
        set videoName = Request.Form("params")("videoName");
        set fromPage = Request.Form("params")("fromPage");
        set fromApp = Request.Form("params")("fromApp");
        set loggedFrom = Request.Form("params")("loggedFrom");
        set timeOfDay = Now;
        var conStr = "Provider=SQLOLEDB.1;Password=xxxxxx;Persist Security Info=True;User ID=xxxxx;Initial Catalog=xxxxx;Data Source=xxxxx";
        con.Open(conStr);
        Set rs = con.Execute("Insert into dbo.tbl_Prospect_Video_Tracking(IPAddress,videoName,fromPage,fromApp,loggedFrom,dtViewed)values('" + ipAddress + "','" + videoName + "','" + fromPage + "','" + fromApp + "','" + loggedFrom + "','" + timeOfDay + "')");
        //alert(insertSQL); 
        rs.close();         
        con.close();
%>

Is there a way for me to test on the P360TradingLog.asp page what might be erroring out? i'm not familiar with these posts so sorry if these seem very lamen.

Was it helpful?

Solution

    <%
    dim con, ipaddress, videoname, frompage, fromapp, loggedfrom, timeofday, constr, sqlstr

    Set con = Server.CreateObject("ADODB.Connection")
    ipAddress = Request.Form("ipAddress")
    videoName = Request.Form("videoName")
    fromPage = Request.Form("fromPage")
    fromApp = Request.Form("fromApp")
    loggedFrom = Request.Form("loggedFrom")
    timeOfDay = Now

    conStr = "Provider=SQLOLEDB.1;Password=xxxxxxx;Persist Security Info=True;User ID=clink;Initial Catalog=xxxxx;Data Source=xxxxx"
    con.Open conStr
    sqlstr = "Insert into dbo.tbl_Prospect_Video_Tracking(IPAddress,videoName,fromPage,fromApp,loggedFrom,dtViewed)values('" & ipAddress & "','" & videoName & "','" & fromPage & "','" & fromApp & "','" & loggedFrom & "','" & timeOfDay & "')"
    con.Execute(sqlstr)


    con.close
    %>

First of all you appear to be using Javascript as your server side scripting language, which is perfectly valid, however I've changed it to VBScript here because I'm a lot more familiar with the syntax.

You're using "set" do declare string variables, which looks wrong. When you use request.form you only use the name of the form field, and you don't need to use a recordset as in this context you aren't retrieving data with a select query

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top