CodeAve.com CodeAve.com - ASP - Miscellaneous
ASP
·Read/Write
·Script Writers
·Database Display
·Response Objects
·Server Variables
·Random Events
·Articles
·Miscellaneous
·Contents
·What's New?
JavaScript
CSS
HTML
Maps
Links
Mail List
Search
Sitemap


 


ASP Output Via JavaScript
JavaScript source code does not need to be embedded into an HTML document. It can reside on the server and be called into a page in a script similar to this <script language = “JavaScript” src = “http://yourserver.com/file_location.js” </script>. Typically, you will see the .js file extension when this technique is used, however JavaScript is not reliant on the .js extension. It can be anything, including .asp. When you target an .asp document instead of a .js document all of the server-side scripting that you put into a “normal” page can be served through JavaScript, providing the .asp output is JavaScript compliant. The added bonus by utilizing this method is that the page serving the .asp through JavaScript does not need to be on the same server, so your content can be utilized remotely. The following example utilizes our db on Hank Greenberg’s career statistics. An Access db will be read and the output will be placed inside document.wite statements. Additionally to avoid people from drilling into the JavaScript source document we check for a document referrer. If there is none then someone has typed the address of the asp directly and they’re given a warning message.
View the Output
Text View
Print View
Mail this Link
Download the Code
View the Data

display-js.html
<html>
<body>
<script language="JavaScript" src="http://www.codeave.com/asp/js-display.asp"></script>
</body>
</html>

js-display.asp
<% 
' If there is no referring page then display the message below 
' and stop all script processing. This is to aid in preventing
' your JavaScript source code from being displayed
if trim(request.servervariables("http_referer")) = "" then 
%>

<html>
<title>Bad request method</title>
<body bgcolor="#FFFFFF">
Error - The information you're requesting can
<br>
not be accessed by this method.
</body>
</html>
<% 
response.end ' stop page completely in there is no referer
end if 'end check for referer

'If there is a valid referer then process request

' Name of the Access db
accessdb="greenberg" 

' Connection to the db
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)

' Create a server record set object
set rs = server.createobject("ADODB.Recordset")

sql = "select * from hammerin_hank " 

' Execute the sql 
rs.Open sql, cn

' Place your HTML output inside document.write(" "); statements
' Be certain to replace all " with either ' or \" in your code
%>

document.write ("<center>");
document.write ("<table border=\"3\">");
document.write ("<caption>Hank Greenberg's Career Statistics</caption><tr>");
<% ' Write out all the elements requested in the 
' sql statement as table headers
for each element in rs.fields %>

document.write ("<th><%= element.name %></th>");
<% next
' End table headers %>

document.write ("</tr>");
document.write ("<tr>");
<% ' Write out all the values in the record 
do while not rs.eof 
for each element in rs.fields %>

document.write ("<td align=right><%= rs(element.name) %></td>");
<% 
next
' end of record %>

document.write ("</tr>");
<% ' Move to the next record
rs.movenext
' Loop to the beginning
loop%>

document.write ("</table>");
document.write ("<br>");
document.write ("* In Military Service");
<% set rs=nothing %>

 

 

 



ASP: What's New? | Articles | Script Writers | Database Display | Read/Write
Server Variables | Response Objects | Random Events | Miscellaneous
HTML: Forms | Hyperlinks | Headers | Tables | Hyperlinks | Headers | Text Display
JavaScript: Document Info | Forms | Images | Navigation | Script Writers
CSS: Basics | Page Display | Text Display | Script Writers | Miscellaneous
  • 2014 michael kors
  • air max women 2013
  • 2014 michael kors
  • air max 2014
  • oakley glasses
  • oakley glasses

  • Maps: Map Script Writers | Bing Maps | Google Maps
  • bottes fr
  • ugg boot
  • Privacy Statement

    CodeAve.com is hosted by MyHosting.com
    Donate Food Online with a Mouse Click at TheHungerSite.com
    Donate Land Online with a Mouse Click at TheRainForestSite.com
    © 1999 - 2017 CodeAve.com
    All Rights Reserved

  • Kids jordan 6 rings
  • Jordan retro 10
  • Jordan retro 3