Created
February 1, 2015 17:22
-
-
Save tenntenn/c303e982d4da8076a6de to your computer and use it in GitHub Desktop.
Firefoxで$.ajaxでCORSなリクエストを投げて,そのレスポンスが302のときにリダイレクトされない。Chromeはされる。生のxhrでもされる。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script> | |
</head> | |
<body> | |
ほげ | |
<script> | |
var xhr = new XMLHttpRequest(); | |
xhr.open("GET", "/hoge", true, "hoge", "fuga"); | |
xhr.send(); | |
$.support.cors = true; | |
$.ajax({ | |
type: "GET", | |
url: "/hoge", | |
success: function(e) { | |
console.log("success"); | |
}, | |
error: function(e) { | |
console.log("error"); | |
} | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
"os" | |
) | |
func hoge(w http.ResponseWriter, r *http.Request) { | |
log.Println("hoge") | |
http.Redirect(w, r, "http://localhost:9090/fuga", http.StatusFound) | |
} | |
func fuga(w http.ResponseWriter, r *http.Request) { | |
w.Header().Set("Access-Control-Allow-Origin", "*") | |
log.Println("fuga") | |
fmt.Fprintf(w, "Fuga OK") | |
} | |
func main() { | |
http.HandleFunc("/hoge", hoge) | |
http.HandleFunc("/fuga", fuga) | |
http.Handle("/", http.FileServer(http.Dir("."))) | |
addr := ":8080" | |
if len(os.Args) > 1 { | |
addr = os.Args[1] | |
} | |
http.ListenAndServe(addr, nil) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment