[英]how to get json string from angular $http post request
我正在發送此POST,我想查看發送之前在請求中發送的字符串。
這是Plunker
$http.post('/someUrl', {msg:'hello word!'}).
then(function(response) {
// this callback will be called asynchronously
// when the response is available
}, function(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
我想我想做的是看到JSON字符串被發送到服務器。
如果您正在使用config選項訪問網址,例如
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);
});
然后,您可以查看發送的數據。 打開瀏覽器console
,單擊“ network
然后在network
下click
您的URL,然后click
Request Payload under header tab
數據將顯示您已發送到服務器的內容。
如果您不使用這樣的配置選項
var data = {
name: 'intekhab',
age:26,
};
$http.post('/admin/header', data).then(function(response){
console.log(response);
});
然后執行與上述相同的操作,唯一的區別是您在Request Payload
下看到了數據,現在您將在Form Data
下看到相同的Form Data
據我了解,我認為您希望請求成功或失敗的處理程序不同。 您可以通過以下方式進行操作:
$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.
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.