我有一个ajax请求,我想使用从服务器端返回的数据。我知道前端代码,但我不知道后端。请帮帮我们! 我的前端代码在这里:
<script>
function login() {
alert("alma");
var sendInfo = {
user: document.getElementById("username"),
passwd: document.getElementById("password")
};
$.ajax({
type: 'POST',
url: 'HalloWorld',
data: sendInfo,
dataType: 'json',
contentType: 'application/.json',
success: function(data) {
//here I want to use my data from sever side
document.getElementById("newdata").innerHTML=data;
},
error: function(jqXHR, textStatus, errorThrown) {
alert("error");
}
});
}
</script>
Username: <input type="text" id="username"/> <br/>
Password: <input type="password" id="password"/> <br/>
<input type="button" value="Login" onclick="login()"/>
<div id="newdata"></div>