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

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

duan1227
duan1227 从哪儿开始?请更新您的问题:格式太可怕了,有大量不必要的代码,没有适当的问题,也没有任何准备工作或任何提示,我们应该在那里找到什么。
9 年多之前 回复
dsgs8208
dsgs8208 真好笑。
9 年多之前 回复

1个回答

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

$.getScript("model.js") 

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

duancong6937
duancong6937 for(j = 0,jl = meshes.length; j <jl; j ++)是正确的语法。 初始化循环,将j设置为0,将jl设置为meshed.length。 如果j <jl,请检查每个重复。 在每次运行结束时,j递增1。
9 年多之前 回复
doubeishuai6598
doubeishuai6598 您需要修复服务器/代码设置以使用“ text / javascript” MIME类型提供js文件
9 年多之前 回复
doukanzhuo4297
doukanzhuo4297 我清除了该内容,但现在我得到了:资源被解释为脚本,但以MIME类型text / html传输。 socket.js:1未捕获的SyntaxError:意外的令牌<
9 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐