我无法在成功时打印 json 对象。但服务器收到了请求。它也可以给出响应。我用海报测试了该服务。请告诉我问题出在哪里?
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
function loginCheck() {
alert("inside function");
$.ajax({
url: "http://localhost:61852/myapp/loginCheck",
type: "POST",
data: "username=username&password=password",
success: function (data) {
alert(data);
}
});
}
</script>
</head>
<body>
<input type="submit" value="submit" onClick="loginCheck();">
</body>
</html>
最佳答案
1. add this dataType :'json' to your ajax parameter, 2. make sure server side response json type,you can force server side response json type in php give a header: header('Content-Type: application/json; charset=utf-8'); echo jsonencode($datasArray))
关于javascript - 成功时无法获取 json 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21928493/