Answer the question
In order to leave comments, you need to log in
How to pass in the response of the Go-server the correct string format for the HTML code?
Here it works fine:
<div id="id_divInner">test div top</div>
<div id="id_divOuter">testDiv_bottom</div>
<button onmouseover="divTopInner()">Ok_test_inner</button>
<button onmouseover="divBottomOuter()">Ok_TestOuter</button>
<script>
function divTopInner() {
document.querySelector('#id_divInner').innerHTML = "<p>test_P_<br>новая строка</p>"; // test_P_ □новая строка
}
function divBottomOuter() {
document.querySelector('#id_divOuter').outerHTML = 'Здесь <a href="#">ссылка-A</a> Outer'; // Здесь ссылка-A Outer
}
</script>
...
xhr.onloadend = function() {
if (xhr.status === 200) {
document.querySelector('#id_divInner').innerHTML = xhr.response; // Тест-ответ сервера со <a href="#">ссылкой-a</a>.<br>Следующая строка.
}
}
http.HandleFunc("/rout", func(w http.ResponseWriter, r *http.Request) {
...
var dataResponRegNo = "Тест-ответ сервера со <a href="#">ссылкой-a</a>.<br>Следующая строка."
var buttonRegs, _ = template.New("dataResp").Parse("{{ .}}")
buttonRegs.Execute(w, dataResponRegNo)
return
}
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