using Ajax to send information to classic ASP

白昼怎懂夜的黑 提交于 2019-12-14 03:17:52

问题


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

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  



});
});

The ASP file code:

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

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?


回答1:


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,
    ...
});

To:

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

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

strID = Request.Form("RecID")

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,
    ...
});

Then receive the param via Request.QueryString():

strID = Request.QueryString("recID")


来源:https://stackoverflow.com/questions/32099820/using-ajax-to-send-information-to-classic-asp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!