2011-07-10 08:01
浏览 147


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 ( 
//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:

        <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 ({ 

        <button>Use Ajax to get and then run a JavaScript</button> 
        <div id="container"> 

socket.js : http://www.grideads.net/redmine/attachments/download/113/socket.js model.js : http://www.grideads.net/redmine/attachments/download/112/model.js

1条回答 默认 最新

相关推荐 更多相似问题