2011-07-10 08:01
浏览 144


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条回答 默认 最新

  • dongshen7561 2011-07-10 08:15

    I did not decode the question, but a possible issue is the way you call your script


    http://localhost:8888/ will call http://localhost:8888/model.js

    http://localhost:8888/static/ajax.html will call http://localhost:8888/static/model.js

    EDIT also your model.js has an error on line 133

    for( j = 0, jl = meshes.length; j < jl; j++ )

    the proper for loop format is

    for (variable=startvalue;variable<=endvalue;variable=variable+increment)

    j < jl; is extra, resulting in the "Unexpected token <" error message

    解决 无用
    打赏 举报

相关推荐 更多相似问题