Javascript 如何从$http post请求中获取json字符串
我正在发送这篇文章,我想在发送之前查看请求中发送的get字符串 这是Javascript 如何从$http post请求中获取json字符串,javascript,json,angularjs,post,request,Javascript,Json,Angularjs,Post,Request,我正在发送这篇文章,我想在发送之前查看请求中发送的get字符串 这是 我想我要做的是看到JSON字符串被发送到服务器。据我所知,如果请求成功或失败,我认为您需要不同的处理程序。您可以这样做: $http.post('/someUrl', {msg:'hello word!'}). success(function(response) { // this callback will be called asynchronously // when it succeeds }
我想我要做的是看到JSON字符串被发送到服务器。据我所知,如果请求成功或失败,我认为您需要不同的处理程序。您可以这样做:
$http.post('/someUrl', {msg:'hello word!'}).
success(function(response) {
// this callback will be called asynchronously
// when it succeeds
}).error(function(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
如果您使用如下配置选项点击url
var config = {
headers: { 'Content-type': 'application/json' },
'dataType': 'json'
};
var data = {
name: 'intekhab',
age:26,
};
$http.post('/admin/header', data, config).then(function(response){
console.log(response);
});
然后您可以看到发送的数据。打开浏览器控制台
并单击网络
,然后在网络
下单击
您所点击的url
现在请参见标题选项卡下的查看请求有效负载
在这里,您的数据将显示您已发送到服务器的内容
如果您没有像这样使用配置选项
var data = {
name: 'intekhab',
age:26,
};
$http.post('/admin/header', data).then(function(response){
console.log(response);
});
然后执行与上面相同的操作,唯一的区别是您在请求有效负载下看到了数据,现在您将在表单数据下看到相同的数据
还不清楚。你想说什么?触摸,现在更清楚了吗?如果你仍然看不见,请告诉我谢谢,我不知道chrome的功能。我可以看到任何请求的所有数据。
var data = {
name: 'intekhab',
age:26,
};
$http.post('/admin/header', data).then(function(response){
console.log(response);
});