未捕获的SyntaxError:意外的令牌<

时间:2011-07-10 08:01:50

标签: javascript html go

我正在运行服务器。当我访问localhost:8888/static/ajax.html时, 我没有错。但是当我刚访问localhost:8888时,我得到了 错误说:

  

“未捕获的SyntaxError:意外   令牌<“

默认情况下,“/”提供ajax.html文件,但这样做我没有得到 预期结果。另一方面我打电话给/static/ajax.html 获得预期的结果没有任何错误。

server.go 包含以下内容:

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 包含以下内容:

<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

1 个答案:

答案 0 :(得分:1)

我没有解码这个问题,但可能的问题是你调用脚本的方式

$.getScript("model.js") 

http://localhost:8888/会致电http://localhost:8888/model.js

http://localhost:8888/static/ajax.html会致电http://localhost:8888/static/model.js

修改 你的model.js在第133行也有错误

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

正确的循环格式是

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

j&lt; JL;是额外的,导致“意外的令牌&lt;”错误消息