簡體   English   中英

使用$ http.get()或$ http.post()通過請求傳遞JSON數據

[英]Passing JSON data with request using $http.get() or $http.post()

我正在嘗試調用要求我向其傳遞JSON對象的Web服務。 盡管我不確定自己是否做對了。 我的服務執行以下操作:

this.updateAddressDetails = function (address, personId) {

    var url = 'http://213.456.123.456:8080/Address?' +
    'action=updateAddress' +
    '&personId=' + personId +
    '&address=' + JSON.stringify(address);

    return $http.get(url);

  }

但是我得到以下錯誤服務器端(我正在使用Java Servlet):

解析HTTP請求標頭時出錯

這使我假設我沒有以正確的方式將JSON傳遞給服務器。 有小費嗎?

如果您正在使用Angular JS,請嘗試如下操作:

$scope.myFunc = function() {

// Simple POST request example (passing data) :
$http.post("/createProject/"+ id +"", {
    projectTitle: pTitle,
    userID      : id
}).
success(function(data, status, headers, config) {
    // this callback will be called asynchronously
    // when the response is available

    console.log("project created");
    console.log("this is the response data " + data);
}).
error(function(data, status, headers, config) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
});
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM