I am running a server on go. When I access the localhost:8888/static/ajax.html
,
I get no errors. But when I just access localhost:8888
I get
an error saying:
"Uncaught SyntaxError: Unexpected token <"
By default "/" serves ajax.html file, but doing so I don't get the
expected result. On the other hand on calling /static/ajax.html
I am
getting the expected result without any errors.
server.go contains the following :
package main
import (
"http"
"flag"
)
//var path = flag.String("storage", "/home/chinmay/work/jstree/", "Set storage directory, use absolute path")
var root = flag.String("root", "/home/chinmay/work/ajax/", "Set root directory, use absolute path")
func temp(w http.ResponseWriter, r *http.Request){
http.ServeFile(w,r,*root +"ajax.html")
}
func main(){
http.HandleFunc("/", temp)
http.Handle("/static/", http.FileServer(*root, "/static/"))
http.ListenAndServe(":8888", nil)
}
ajax.html contains the following:
<html>
<head>
<script type="text/javascript" src="/static/jquery.js"></script>
<script type="text/javascript" src="/static/three/Three.js"></script>
<script type="text/javascript" src="/static/js/Detector.js"></script>
<script type="text/javascript" src="/static/js/RequestAnimationFrame.js"></script>
<script type="text/javascript" src="/static/js/Stats.js"></script>
<script type="text/javascript">
$.ajaxSetup ({
cache:false;
})
$("#container").ready(function(){
$("button").click(function(){
$.getScript("model.js");
});
});
</script>
</head>
<body>
<button>Use Ajax to get and then run a JavaScript</button>
<div id="container">
</div>
</body>
</html>
socket.js : http://www.grideads.net/redmine/attachments/download/113/socket.js model.js : http://www.grideads.net/redmine/attachments/download/112/model.js