Answer the question
In order to leave comments, you need to log in
Why doesn't the golang server send a response?
There is a golang server:
package main
import (
"fmt"
"net/http"
)
var i = 0
func receiveSend(w http.ResponseWriter, r *http.Request) {
if r.Method == "POST" {
sendedData := r.FormValue("sendedData")
fmt.Println("My request is: ", sendedData)
fmt.Fprintln(w,"sd")
}
}
func main() {
http.HandleFunc("/", receiveSend)
http.ListenAndServe(":8000", nil)
}
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<body>
<button id="send">Send</button>
<p class="results">Ждем ответа</p>
</body>
<script>
var data;
$('#send').click(function() {
$.ajax({
url: "http://localhost:8000",
method: "POST",
data : { sendedData: 'Hello'},
success : function(data) {
$('.results').html(data);
},
});
});
</script>
</html>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question