GO: javascript and html MIME error -


I am trying to load JavaScript in my GO app, but I got an error:

 The  resource has been interpreted as a script but the mime type has been transferred with text / html: "http: // localhost: 4747 / twttr.js" localhost /: 6 unwanted syntax error: unexpected token & lt ; Package main import ("net / http" "html / template") func main () {http.HandleFunc ("/" /> , handler) http.ListenAndServe (": 4747", zero)} function controller (W., R, "twttr.js") return} t, _: = template. Parasfoil ("home.html", "edit.html") t. Exquisite (w, map [string] string {"title": "my headline", "body": "hi it's my body"}}}  

In my html, Is:

     gt; title & gt; Twitter & lt; / title & Gt; & lt; script src = "http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" & gt; & lt; / script & gt; & lt; script Type = "text / javascript" src = "twttr.js" & gt; & lt; / script> gt; top & gt; body; gt; & lt; h1 & gt; add new tweet & Lt; / h1 & gt; & lt; form action = "/ save / {{title}}" Method = "to get" & gt; Button type = "button" value = "edit" class = "etting"> Add tweet! & Lt; / button> & gt; / form & gt; ; Title {{.title}} {{template "edit html"}}  << html>  

js:

  $ (document) .ready (function () {$ ('addtweet'). Click (function () {alert ("for handler. Click "().");});})  

Directory structure:

  static / home.html twttr.js twttr Go  

I have to do something about how I display the template / html in the GO app. But I do not know the exact problem. New, so any guidance is highly appreciated!

If you are the result of loading JS file , what Also there is a expected file? I do not think you are handling it, based on the code posted, I do not think you have posted anything until you have the same result for each request including the JS file.

To serve the file through Geo, consider:

You will have to check the URL and handle it accordingly. Example:

  if r.URL.Path == "/twttr.js" {http.ServeFile (w, r, "static / twttr.js") returns} t, _: = Template: Parasphile ("home.html", "edit.html") t.Execute (w, map [string] string {"title": "my title", "body": "Hi this is my body"} < / Code> 

Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -