使用Ajax将信息发送到经典ASP

使用Ajax将信息发送到经典ASP

问题描述:

我的html表格上有一个重置按钮.单击它时,它将获取与其行相关的信息,尤其是记录ID"和活动".我正在尝试获取记录的ID号并将其发送到名为resetinbound.asp

I have a reset button on my html table. When it's clicked, it gets information related to its row, particularly the 'record ID' and 'Active'. I'm trying to take the record Id number and send it to my asp page called resetinbound.asp

这是我第一次使用AJAX,所以我不确定我在做什么是否正确,但这是单击时"的代码:

This is my first time using AJAX so I'm not sure if what I'm doing is correct but here is the code for the On Click:

 $(function(){
$('button').on('click', function(){
    var tr = $(this).closest('tr');
    var RecID = tr.find('.RecID').text();
    var active = tr.find('.active').text();
    alert('id: '+RecID+', Active: ' + active);

$.ajax({
            type: "POST",
             url: "resetInbound.asp",
             data: RecID,
             success: function() { 
                alert("I am back after sending data sucessfully to server.");}
             });
      // Ajax call ends  



});
});

ASP文件代码:

Dim RecID
RecID = Request.QueryString("RecID")

我也尝试了Request.Form和Request.BinaryRead,但是它们都不起作用.似乎代码甚至根本无法到达ASP页面.我在做什么错了?

I also tried Request.Form and Request.BinaryRead but none of them worked. It seems like the code doesn't even reach the ASP page at all. What am I doing wrong?

AJAX参数的data成员必须是一个指定每个参数的名称和值的对象.因此,您需要更改此内容:

The data member of your AJAX param needs to be an object that specifies the name and value of each parameter. So you'll need to change this:

$.ajax({
    type: "POST",
    url: "resetInbound.asp",
    data: RecID,
    ...
});

收件人:

$.ajax({
    type: "POST",
    url: "resetInbound.asp",
    data: { "RecID": RecID },
    ...
});

然后您应该在ASP页面中收到一个命名参数:

And then you should receive a named parameter in your ASP page:

strID = Request.Form("RecID")


但是,如果要使调试变得更容易,请使用GET而不是POST并通过querystring/URL传递值:


If you want to make things easier to debug, however, use GET instead of POST and pass your values via querystring/URL:

$.ajax({
    type: "GET",
    url: "resetInbound.asp?recID=" + RecID,
    ...
});

然后通过Request.QueryString()接收参数:

strID = Request.QueryString("recID")