duandou8120 2011-07-10 08:01
浏览 154
已采纳

未捕获到的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

  • 写回答

1条回答 默认 最新

  • dongshen7561 2011-07-10 08:15
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘