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 求解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波