How to handle the response from the web server (ajax)?

Request to the server, it responds, the response sends the html code of the page you want to go, how the answer to process what happened to the transition? After my request he just sent me the html and all. Google did not help. Always write your add handler, and everywhere about json and how do I html it treat?

var msg = $('#t_data').serialize();
$.ajax({
async: false,
type: 'POST',
url: '127.0.0.1',
data: msg,
success: function(data) {
alert(data);

data.responseText;
},
error: function(xhr, str){
alert('error Occurred:' + xhr.responseCode);
}
});
July 2nd 19 at 17:24
1 answer
July 2nd 19 at 17:26
Judging from 127.0.0.1, you made such a strange server, one wonders why you made the server without thinking? Now you see that with this server it is not possible to work via AJAX, why do you not think that maybe the server need to fix?
In principle, JSON is not mandatory and it is possible with HTML, but it will not "transition", "transition" is only with page reload, and you need to edit the DOM, like this:
document.getElementById('container').innerHTML = htmlResp;

htmlResp - string with the server response (responseText), of course it should contain the entire HTML page, but only what should be in a container.

Find more questions by tags AJAXjQueryJavaScript