ASP Dictionary Object Problem - I can't get the Items() and Keys() methods to work...
Hi,
I'm currently trying to make a template parser in ASP written with Javascript. I used the dictionary object to keep track of the variable to be parsed, but I can't get the available keys using obj.Keys().
The code is below:
var avaiVar = Server.CreateObject("Scripting.Dictionary");
avaiVar.Add("test", "hello");
avaiVar.Add("name", "joe");
var arr = avaiVar.Keys();
for (i = 0; i < avaiVar.Count; i++) {
Response.Write(arr[i]);
}
It doesn't output anything.... The code is taken itself from the ASP Jscript reference. Chad? Can you please help me?
Thanks in advance.
Anonymous posted this at 18:51 — 29th August 1999.
They have: 5,633 posts
Joined: Jan 1970
The coding looks good at first glance (minus the smiley faces ) Two things that I can see that may be a problem:
1) You do have this within the <% %> tags, correct?
2) Is the Scripting.Dictionary component installed on your providors server for use? I am not sure if this component comes with IIS and ASP or if it is a seperate one made by a third-party company.
PJ posted this at 20:47 — 30th August 1999.
They have: 76 posts
Joined: Apr 1999
elara,
Just because a component is included (default) with IIS/ASP doesn't mean your host supports it.
A couple of weeks ago I was going crazy trying to figure out why my CDONTS script wasn't working (CDONTS is also a component of IIS/ASP used for creating mail objects on the server). After a lot of frustation I sent an email to the hosting service (Powersurge.net) asking them if they didn't support CDONTS, guess what, they don't. The good news was they had ASPMail which is a little bit better anyways.
I would just double check with your host to see if they've disabled this component.
You have changed the default server scripting language to Javascript right? It's VBScript by default.
Later,
PJ
elara posted this at 03:28 — 31st August 1999.
They have: 112 posts
Joined: Apr 1999
Yup, I have included the <% and %> tag, and the dictionary object is a default component in ASP.
Thanx for your help, Chad
Regards.
Anonymous posted this at 23:36 — 31st August 1999.
They have: 5,633 posts
Joined: Jan 1970
In the same logic as you i write for a one but in VBScript version, it work! see:
<%
dim avaiVar
set avaiVar = Server.CreateObject("Scripting.Dictionary")
avaiVar.Add "test", "hello"
avaiVar.Add "name", "joe"
arr = avaiVar.Keys
for i = 0 to avaiVar.Count - 1
Response.Write arr( i )
next
%>
when i try to translate this code back to JavaScript...
it give me the undefined answer... i think the problem is come out in your line:
var arr = avaiVar.Keys();
since i try to output something in JavaScript, it work:
Response.Write( avaiVar("test" ) )
there should be a something problem of the ASP component and JavaScript array architecture...would you mind call it is a bug??
William Ng
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.