Hi guys im just new with asp classic and jquery and am just wondering if there is a way wherein i can pass my collection variables to jquery. my goal is to make the variables slide down one at a time. I came across the .slideDown function on jquery so i tried using it but doesn't seem to work so i guess what's wrong is my mark up... any help will be greatly appreciated.
ASP CODE:
<%
Dim objDictionary, Key,searchWord, myVar,a,i, break
searchWord = request.QueryString("searchWord")
break = Response.write("<br />")
Set objDictionary = CreateObject("Scripting.Dictionary")
objDictionary.CompareMode=1
objDictionary.Add "Hello","hello"
objDictionary.Add "Age","age"
objDictionary.Add "height","height"
objDictionary.Add "sample","sample"
objDictionary.Add "words","words"
if objDictionary.Exists(searchWord) then
objDictionary.Remove(searchWord)
a = objDictionary.Keys
for i=0 to objDictionary.Count-1
Response.Write(a(i))
break
next
set objDictionary=nothing
else
a = objDictionary.Keys
for i=0 to objDictionary.Count-1
Response.Write(a(i))
break
next
set objDictionary=nothing
end if
%>
JQUERY CODE:
<script type="text/javascript">
$(document).ready(function(){
$("#toFall").slideDown("slow");});
</script>
Have you tried placing each dictionary key in some kind of DOM container, like a div - each of which are children of #toFall, eg:
Response.write "<div id='#toFall'>"
for i=0 to objDictionary.Count-1
Response.Write "<div>" + (a(i)) + "</div>"
next
Response.write "</div>"
^^Please double check the syntax - my VBScript is rusty. Also - are you sure you want that break in the loop - doesn't that mean only one write occurs?
Here is a generic method that will send any classic ASP collection (with Keys and values) to be a JavaScript collection:
Sub CollectionToJavaScript(oCollection, sClientSideName)
Dim blnFirst
blnFirst = True
Response.Write("<" & "script" & " type=""text/javascript"">")
Response.Write("var " & sClientSideName & " = {")
For Each key In objDictionary.Keys
If Not(blnFirst) Then Response.Write(", ")
Response.Write("""" & key & """: """ & objDictionary(key) & """")
blnFirst = False
Next
Response.Write("};")
Response.Write("</" & "script>")
End Sub
First parameter is the collection, second is the desired name of the client side variable to hold the JavaScript collection.
This will create client side complex object that can be later accessed using the name you provided as the second parameter of the above method.
General way to debug that it's working:
<script type="text/javascript">
for (var key in myCollection) {
alert("key is " + key + " and value is " + myCollection[key]);
}
</script>
In your case, you should call this method like that after populating the collection:
Call CollectionToJavaScript (objDictionary, "myCollection")
Then in your jQuery, assuming you want to slide down all the keys (ie all keys are valid DOM elements) have such code:
$(document).ready(function() {
for (var key in myCollection) {
$("#" + key).slideDown("slow");
}
});
If you also need the value associated with each key, access it by using myCollection[key]
in the loop.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.