javascript - should I add ns_return / ns_respond to my code? -
i new learning tcl , adp ,, ajax code not returning result tcl file though sends request thought maybe should add command response , please assist me below code :
<html> <body> <form action=""> <input value="get time" type="button" onclick="showcurrenttime();" name="gettime"> <div id="result" align="center"></div> </form> <script language="javascript"> function showcurrenttime() { var xmlhttp; if (window.xmlhttprequest) { xmlhttp=new xmlhttprequest(); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("result").innerhtml=xmlhttp.responsetext; } xmlhttp.open("get","time.tcl",true); xmlhttp.send(); } } </script> </body>
please note tcl file working print time , if need add commands ns_return or command ns_respond please add explanation , in advance :)
you might find easier use jquery library in javascript, allows write client-side code more succinctly. (note put links used in javascript in <head>
section , pull them in reference aids debugging in complex cases.)
<html> <head> <script src="jquery.js"></script> <link id="timer" href="time.tcl" /> </head> <body> <form action=""> <input value="get time" type="button" onclick="showcurrenttime();" name="gettime"> <div id="result" align="center"></div> </form> <script language="javascript"> var timerurl = $("#timer")[0].href; function showcurrenttime() { $.get(timerurl, function(response) { $("#result").html(response); }); } </script> </body>
next, need check content type of response server is. should make sure text/plain
if i've understood you're trying in case. if i've read documentation ns_respond
right, want like:
ns_respond -type "text/plain" -string [clock format [clock seconds]]
more generally, returning json more useful though want different techniques displaying it.
Comments
Post a Comment