在经典ASP页面上检索AJAX发布数据

时间:2014-03-19 14:06:42

标签: jquery ajax post asp-classic request.form

我正在做的是取决于点击的链接,重新构建URL并从URL读取变量,然后对经典ASP页面进行AJAX调用,然后将post值插入SQL数据库中。

这是在document.ready()函数中,这样当URL被更改时,它将读入新值;

        //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 []似乎在执行

时正确包含数据
alert(params["logVideo"]);

它返回正确的值,但我没有收到"这篇文章成功了#34;警报。我的问题是我的代码应该在p360TradingLog.asp页面中,以获取这些发布的值并正确插入它们?这是我当前的代码,但无法正常工作。

<%
        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();
%>

我有没有办法在P360TradingLog.asp页面上测试可能出错的内容?我对这些帖子不太熟悉,如果这些帖子看起来非常落伍,那就很抱歉。

1 个答案:

答案 0 :(得分:1)

    <%
    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
    %>

首先,您似乎使用Javascript作为服务器端脚本语言,这完全有效,但我已将其更改为VBScript,因为我对语法更熟悉。

您正在使用&#34;设置&#34;声明字符串变量,看起来不对。当您使用request.form时,您只使用表单字段的名称,并且您不需要使用记录集,因为在此上下文中您不能使用选择查询检索数据