简体   繁体   English

如何使用JavaScript发布到Classic ASP中的数据库

[英]How can I post to a databse in Classic ASP using JavaScript

I have a sortable list that allows me to rearrange the items by dragging and dropping them. 我有一个可排序的列表,可以通过拖放来重新排列项目。 When I rearrange the items, the number inside the input tags adjust according to their new position within the list. 重新排列项目时,输入标签内的数字会根据它们在列表中的新位置进行调整。 AT this point what I'd like to do is post the new input value(s) to a field within my database. 在这一点上,我想做的就是将新的输入值发布到数据库中的字段中。

Below is the Classic ASP code 以下是经典的ASP代码

<form name="sort_award" action="file_2.asp?Action=sort" method="post">
<%
end if
response.write "<ul id='sortable'>"
dim i
i=1

While not rsAwards.EOF

response.write "<li onclick='sort("&rsAwards("Award_ID")&")'> &nbsp 
<input type='text' name='AwardNumber' size='1' value="&i&"> &nbsp 
<label name='AwardName'>" & rsAwards("Award_Name") & "</label>"
%>
<a href='edit_awards.asp?Action=edit&Award_ID=<%=rsAwards("Award_ID")%>' name='AwardID'>Edit</a>&nbsp;
<a class="lb" href='file_1.asp?Action=delete&Award_ID=<%=rsAwards("Award_ID")%>'>Delete</a></li>
<%
rsAwards.MoveNext
i=i+1
Wend

%></ul>
<input type="submit" value="Sort">
</form>

And here is the JavaScript 这是JavaScript

$(function() {
    $( "#sortable" ).sortable({ placeholder: "ui-state-highlight" });
});

function sort(AwardID) {
  var count = document.getElementById('sortable').getElementsByTagName('li').length;
  var AwardNum = document.getElementById('sortable').getElementsByTagName('input');

    for(var i = 0; i < count; i++)
    {
      AwardNum[i].setAttribute('value', i+1);     
    }
 }

Use jQuery . 使用jQuery

You can easily post data through ajax to your asp page by using .post() 您可以使用.post()通过ajax将数据轻松发布到asp页面。

If you are doing a get request, then you can use .get() instead, it is much less complicated. 如果要执行get请求,则可以改用.get() ,它要简单得多。

(NOTE: jQuery includes a bunch of other ajax request functions as well, like .ajax() , .load() , etc. but I find .get() to be my go to function for this because it allows more flexibility and usage functions are needed to remember) (注意:jQuery还包括许多其他ajax请求函数,例如.ajax() .load()等。但是我发现.get()是我的.get() ,因为它允许更多的灵活性和使用性需要记住的功能)

To use it, simply do this: 要使用它,只需执行以下操作:

<script>
$.get("myasppage.asp?id=12345", function(data){

   //after the request is complete, you can place any code here that you want
   //therefore, your code won't continue processing until the request is done.

   //if the .asp page returns content like "HELLO!", then that would be in your
   // data variable, as defined up top.  So you can just do this.


   $(body).append(data); //<- appends the data from myasppage.asp to your body content

   alert(data); // <- will popup an alert box with the content returned from your asp page



});
</script>

That's it. 而已。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM