2014-10-20 37 views
0

我的代碼是這樣的

$http.post("../services/myurl.aspx?Param=" + finaldata, '', { 'Content-type': 'text' }) 
.success(function (pricedata) { 
    alert (success)       
}) 
.error(function() { 
    alert('we have failed to make a connection with the server. Please try after some time'); 
}); 

當我做這個呼叫成功,也沒有錯誤既不happens.But服務被調用。我有點困惑。任何人都可以指出我做錯了什麼?

+0

你有什麼錯誤?請檢查瀏覽器控制檯錯誤? – 2014-10-20 07:44:14

+0

你可能想在'alert'中引用'success'的引號。 – 2014-10-20 07:47:50

回答

0

你應該使用服務來發布數據,這裏是你如何做到這一點。

doSomething: function (data, url) { 
      return $http({ 
       url: url, 
       method: 'POST', 
       data: data 
      }); 
     }, 

,並在控制器消費此服務爲

someService.doSomething($scope.MyData, $scope.Url) 
     .success(function (response) { 
      console.log("Success", response); 
     }) 
     .error(function (data, status, headers, config) { 
      console.log("Error"); 
     }); 
+0

+1用於標準編碼。但OP不知道「someService」的意思。 – 2014-10-20 08:08:46

0

試試這個簡單的代碼....

 $http({ 
      method: 'POST', 
      url: "../services/myurl.aspx?Param=" + finaldata, 
     }) 
     .success(function (data, status, headers, config) { 
     var success="success" 
      alert (success);// or alert("success") 
     }) 
     .error(function (data, status, headers, config) { 
      alert('we have failed to make a connection with server. Please try after some time'); 
     }); 
相關問題