2014-10-20 49 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'); 
     }); 
相关问题