【发布时间】:2015-07-05 03:07:53
【问题描述】:
我想从基于 nodejs 服务器的 ajax 客户端获取我发布的 JSON 对象的内容。
如果我在客户端有以下代码:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
$('#form').click(function(e){
e.preventDefault();
hellodata = {
id : '1234',
content: 'hello'
};
$.ajax({
url : "http://localhost:3000/savedata",
type: "POST",
data : hellodata,
success: function(data, textStatus, jqXHR)
{
//data - response from server
},
error: function (jqXHR, textStatus, errorThrown)
{
}
});
});
</script>
如何获取服务器端的参数id和内容?
server.post("/savedata", function(req, res){
//I get here after doing the ajax post and I want to show here the content of hellodata json
});
谢谢!
【问题讨论】:
-
你在使用
express? -
是的,我正在使用快递
-
您没有发布 JSON。您正在发布表单编码数据。
标签: javascript json node.js express