chuhuodan.asp 頁面
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.js"></script>
<script>
function ajaxPost(id){
$.ajax({
url:'savewancheng.asp',
data:{id:id},
type:'POST',
dataType:'text',
error:function(xhr){alert('錯誤\n'+xhr.responseText)}
})
}
</script>
請問以上這一段如何才能 同時提交 id 和 checkbox 兩個變數?
<%if rs("wancheng")=0 then %>
<form name="form1" method="post" action=""><input type="checkbox" name="checkbox" value="https://bbs.csdn.net/topics/0" onclick="ajaxPost(<%=rs("_identify")%>)"></form>
<%else %>
<form name="form1" method="post" action=""><input type="checkbox" name="checkbox" value="https://bbs.csdn.net/topics/1" checked="CHECKED" onclick="ajaxPost(<%=rs("_identify")%>)"></form>
<%end if %>
savewancheng.asp 頁面
<!--#include file="conn2.asp"-->
<%
id=request("id")
wancheng=request("wancheng")
set rs2=server.CreateObject("adodb.recordset")
rs2.Open "select * from chuhuodan where _identify='"&id&"'",conn2,1,3
if wancheng=1 then
rs2("wancheng")=1
else rs2("wancheng")=0
end if
rs2.Update
rs2.movenext
rs2.Close
set rs2=nothing
%>
uj5u.com熱心網友回復:
1. 直接在onclick里面多加個引數2. 在ajaxPost里面獲取checkbox的值添加到data: {id:id, checkbox: checkbox}
uj5u.com熱心網友回復:
<script>function ajaxPost(id,checkbox){
$.ajax({
url:'savewancheng.asp',
data:{id:id,checkbox:checkbox},
type:'POST',
dataType:'text',
error:function(xhr){alert('錯誤\n'+xhr.responseText)}
})
}
</script>
<%if rs("wancheng")=0 then %>
<form name="form1" method="post" action=""><input type="checkbox" name="checkbox" value="https://bbs.csdn.net/topics/0" onclick="ajaxPost(<%=rs("_identify")%>,0)"></form>
<%else %>
<form name="form1" method="post" action=""><input type="checkbox" name="checkbox" value="https://bbs.csdn.net/topics/1" checked="CHECKED" onclick="ajaxPost(<%=rs("_identify")%>,1)"></form>
<%end if %>
這樣不行?
uj5u.com熱心網友回復:
不行?其實就現在的代碼form和checkbox也沒必要,傳到api的值是寫死的,并不會根據checkbox變化而變化,onclick是點擊checkbox就觸發。uj5u.com熱心網友回復:
<%if rs("wancheng")=0 then %><form name="form1" method="post" action=""><input type="checkbox" name="checkbox" value="https://bbs.csdn.net/topics/1" onclick="ajaxPost(<%=rs("_identify")%>,1)"></form>
<%else %>
<form name="form1" method="post" action=""><input type="checkbox" name="checkbox" value="https://bbs.csdn.net/topics/0" checked="CHECKED" onclick="ajaxPost(<%=rs("_identify")%>,0)"></form>
<%end if %>
可以了,謝謝!是邏輯搞反了。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/186751.html
標籤:Ajax
下一篇:萌新發現新世界
