我尝试将 200 OK 响应发送回 chrome 浏览器,但浏览器没有像我预期的那样做出反应,他清理屏幕而不是更改特定的“div”,这是我的代码:
我的服务器:(node.js):
function postHandler(request, response) {
request.on('data', function(data) {
body += data;
var parseBody = queryString.parse(body);
response.writeHead(200, {"Content-Type": "text/plain"});
response.end("<div>divi</div>");
});
response.on('end', function() {
console.log("End_Body: " + body);
});
}
我的 JavaScript 浏览器 ajax 调用看起来像:
$(document).ready(function() {
$("#register_form").ketchup();
var request;
$("#submit_btn")
.on('click',function() {
var username = $('#reg_username').val();
var password = $('#reg_password').val();
var firstname = $('#firstname').val();
var lastname = $('#lastname').val();
var age = $('#age').val();
request = $.ajax({ url: "/welcome.html",
type: "POST",
data: {
'username': username,
'password': password,
'firstname': firstname,
'lastname': lastname,
'age': age
}});
request.done(function (response, textStatus, jqXHR){
$("#server_answer").text("success");
});
request.fail(function (jqXHR, textStatus, errorThrown){
$("#server_answer").text("fail");
});
});
});
我究竟做错了什么?