我有一个可排序的列表,允许我通过拖放它们来重新排列项目。当我重新排列项目时,输入标签中的数字会根据它们在列表中的新位置进行调整。此时,我要做的是将新的输入值张贴到数据库中的一个字段中。
下面是经典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")&")'>  
<input type='text' name='AwardNumber' size='1' value="&i&">  
<label name='AwardName'>" & rsAwards("Award_Name") & "</label>"
%>
<a href='edit_awards.asp?Action=edit&Award_ID=<%=rsAwards("Award_ID")%>' name='AwardID'>Edit</a>
<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
$(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);
}
}
发布于 2014-01-23 21:08:41
使用jQuery。
您可以使用.post()
轻松地通过ajax将数据发布到asp页面。
如果您正在执行get请求,那么您可以使用.get()
来代替它,这样就不那么复杂了。
(注意: jQuery还包括许多其他ajax请求函数,如.ajax()
、.load()
等,但我发现.get()
是我的函数,因为它允许更多的灵活性和需要记住的使用函数)
要使用它,只需这样做:
<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>
就这样。:)
https://stackoverflow.com/questions/21316030
复制