首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用JavaScript向经典ASP中的数据库发布

如何使用JavaScript向经典ASP中的数据库发布
EN

Stack Overflow用户
提问于 2014-01-23 18:05:10
回答 1查看 172关注 0票数 0

我有一个可排序的列表,允许我通过拖放它们来重新排列项目。当我重新排列项目时,输入标签中的数字会根据它们在列表中的新位置进行调整。此时,我要做的是将新的输入值张贴到数据库中的一个字段中。

下面是经典ASP代码

代码语言:javascript
运行
复制
<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>

这是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);     
    }
 }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-24 05:08:41

使用jQuery

您可以使用.post()轻松地通过ajax将数据发布到asp页面。

如果您正在执行get请求,那么您可以使用.get()来代替它,这样就不那么复杂了。

(注意: jQuery还包括许多其他ajax请求函数,如.ajax().load()等,但我发现.get()是我的函数,因为它允许更多的灵活性和需要记住的使用函数)

要使用它,只需这样做:

代码语言:javascript
运行
复制
<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>

就这样。:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21316030

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档