2014-09-05 50 views
0

当我通过$ http服务将数据发布到AngularJS中时,表单数据被添加在我的实际URL之前。因此,无论我的帖子是否成功,我都会重定向到我的默认路由页面。

通常我的URL格式就像下面,

http://localhost:4695/#/system/home/dashboard 

当我发帖的形式,它变得像,

http://localhost:4695/?companyFullName=&name=&position=#/system/home/dashboard

这是我后我的形式。

$http.post('http://localhost:2795/api/company', data, { headers: { 'Content-Type': 'application/json; charset=utf-8' } }); 

回答

0

我的表单标记具有以下操作属性。

action="#" 

我基本上删除了action属性,我的网址中不再有数据。

0
$scope.formParams = { 
    ... 
} 

$http.post('http://localhost:2795/api/company',$.param($scope.formParams),{headers : {'Content-Type' : 'application/x-www-form-urlencoded'}}).then(function(response){ 
    [Success Stuff Here] 
},function(response){ 
    [Error Stuff Here] 
}); 

使用jQuery的$.param函数来打包表单的数据。