我想发布数据并在浏览器上显示服务器发送的http响应,但我卡在浏览器上没有显示任何内容
我通过wire shark检查服务器正在发送json响应,但浏览器上没有显示任何内容,我想获取响应正文并解析它,然后将其显示给用户。
有没有办法获取表单详细信息,然后将其包装在变量上并将其发布到服务器
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.post(
"http://192.168.0.135:8080/uid",
{
"type" : "CREATE_ACCOUNT",
"data" : '{ "hardwareID" : "SAM1234567890123", "name" : "Jain", "emailID" : "jain@gmail.com", "password" : "dgbedbeifkfk" }'
},
function(data,status) {
alert("Data: " + data + "\nStatus: " + status);
}
);
});
});
</script>
</head>
<body>
<button>Send an HTTP POST request to a page and get the result back</button>
</body>
</html>
请您参考如下方法:
只是想让您知道,您的 JSON 无效,这是您的 JSON 的正确版本:
{
"type": "CREATE_ACCOUNT",
"data": {
"hardwareID": "SAM1234567890123",
"name": "Jain",
"emailID": "jain@gmail.com",
"password": "dgbedbeifkfk"
}
}
删除“数据”行中 { 前面的 '。
我强烈建议您在搜索其他错误之前通过 jsonLint.com 验证您的 JSON。
