Javascript kullanırken “src=xxx.js” parametresini kullanarak birden fazla sayfada kullandığımız javascript fonksiyonlarını tek bir dosyada toplayabiliriz. Ancak bu statik bir çözümdür ve birçok sayfada dinamik bilgilere ihtiyaç duyarız.Bu yüzden işin içine Asp ‘ yi katarak database de dahil olmak üzere tüm server-side teknolojileri kullanarak çok daha esnek javascript uygulamaları yazabiliriz.
Örneğin havadurumu bilgilerini içeren bir siteniz var (havadurumu.com) ve başka sitelerin de bu bilgileri kullanabilmesini istiyorsunuz. Bunun için bir web servisi yaratabilir ve xml aracılığıyla bilgi alışverişi yapabilirsiniz. Ancak bu tip basit uygulamalarda Asp & Javascript kullanarak oldukça kolay çözümler üretmek daha mantıklıdır.
Örneğin bir müşteriniz sizin hava durumu bilgilerinizin belli bir ücret karşılığında kendi sitesinde de olmasını istiyor. Bu işi müşterinizin sayfasında hiçbir asp kodu olmadan ( connection string’ i vermek istemezsiniz

)) halledebilirsiniz. Yani Asp destekleyen bir sunucuda olması gerekmez. Çünkü müşterinin sayfasındaki kod tamamen client-side çalışır.
Örneğimizde hava durumu bilgileri “hava.mdb” dosyasında durmaktadır. “Hava.asp” dosyası db’ den havadurumu bilgilerini çekip response.write ile javascript ile kullanabileceğimiz client-side değişkenlere atar. “index.html” sayfasında da bu bilgileri document.write metoduyla sayfada istediğimiz yere yazdırabiliriz.
PLAIN TEXT ASP:- <LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]<%@ LANGUAGE=”VBSCRIPT”%>[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]<%[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]dim constr[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]constr=”provider=microsoft.jet.oledb.4.0;data source=” & server.MapPath(”hava.mdb”)[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace] [/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]dim con[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]dim rst[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]dim sql[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]dim ist1,ist2,ank1,ank2[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace] [/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace] [/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]set con=server.createobject(”adodb.connection”)[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]set rst=server.createobject(”adodb.recordset”)[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]con.open constr[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace] [/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]sql=”select top 2 derece1,derece2 from hava where datevalue(tarih)=’”& datevalue(date()) &”‘ order by sira”[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace] [/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]rst.open sql,con[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace] [/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]if not rst.eof then[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]ist1=rst.Fields(”derece1″).Value[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]ist2=rst.Fields(”derece2″).Value[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]rst.MoveNext[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]if not rst.EOF then[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]ank1=rst.Fields(”derece1″).Value[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]ank2=rst.Fields(”derece2″).Value[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]end if[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]end if[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace] [/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]set rst=nothing[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]set con=nothing[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]%>[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]<!–[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]var istHava=”<%=ist1%>” + “/” + “<%=ist2%>”;[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]var ankHava=”<%=ank1%>” + “/” + “<%=ank2%>”;[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]//–>[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]index.html[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace] [/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]<html>[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]<body>[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]<head>[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]<script language=”javascript” src=”hava.asp”></script>[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]</head>[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]</body><body>[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]HAVA DURUMU<br /><br />[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]İstanbul : <script language=”javascript”>document.write(istHava);</script>[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]<br />[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]Ankara : <script language=”javascript”>document.write(ankHava);</script>[/FONT]
<LI style="FONT-WEIGHT: normal; COLOR: #f73b3b; FONT-STYLE: normal; FONT-FAMILY: 'Courier New', Courier, monospace">[FONT='Courier New', Courier, monospace]<br />[/FONT]
<LI style="FONT-WEIGHT: bold; COLOR: #7bbe54">[FONT='Courier New', Courier, monospace]</body>[/FONT] - [FONT='Courier New', Courier, monospace]</html> [/FONT]
Gördüğünüz gibi hiç asp kodu olmamasına rağmen html sayfamızdaki havadurumu bilgileri dinamik olarak gelmektedir.
Bu örnek aynı klasörde olan “hava.asp” dosyasının çağırmaktadır. Başka bir siteden bu bilgileri almak için
PLAIN TEXT CODE:- [FONT='Courier New', Courier, monospace]<script language=”javascript” src=”hava.asp”></script> [/FONT]
satırını
PLAIN TEXT CODE:- [FONT='Courier New', Courier, monospace]<script language=”javascript” src=”http://www.havadurumu.com/hava.asp”></script> [/FONT]
olarak değiştirmemiz yetecektir.