Reputation: 9869
Good day,
I am confused as to when I am using VBScript, Javascript, and JScript inside classic ASP.
I've been told that our environment uses JScript by default.
So when we create a blank page with our company's standard includes, we just start coding in JScript.
Now I wish to use the json2.js file so that I can parse incoming JSON and send JSON out to clients/browsers.
I didn't think that I needed to do anything special to use json2.js since it's pure javascript. But I'm having issues placing the SCRIPT tag. Basically when and where do I need a new SCRIPT tag inside a classic ASP page?
I am getting a 'JSON' is null or not an object' response. That leads me to believe that the JSON.parse() method is not even being recognized.
Thanks
<script language="javascript" runat="server" src="json2.js"></script>
<%
.... ..... some ASP Code in JScript
%>
<script language="javascript" runat="server">
var lngBytesCount
lngBytesCount = Request.TotalBytes
var requestBody = BytesToStr(Request.BinaryRead(lngBytesCount));
//var jsonObject=JSON.parse(\"{"answer":"ok"}\");
var jsonObject=JSON.parse(requestBody);
Response.ContentType = "application/json";
for (var i in jsonObject){
Response.Write(jsonObject[i]);
}
//var json = eval(requestBody);
//Response.Write(json);
Response.End()
</script>
<%
.... ..... some ASP Code in JScript
Upvotes: 2
Views: 2424
Reputation: 4384
It depends on whether you want to use the json2.js library client side or server-side.
Classic ASP is a server-side technology that supports different languages, the most popuplar being vbscript and jscript. This is the same as ASP.NET which can be written in C# or VB.
The code between <%
and %>
tags is executed server side. Also, blocks of code between <script runat="server">
and </script>
run server side.
If you leave out the runat="server"
part, it runs client-side, and it is executed by the client browser.
So to answer your question, if you want to use it server-side; use <script runat="server">
, if you want o use it client-side use <script>
Upvotes: 2