Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular:将curl转换为Angular$http POST请求_Javascript_Ajax_Angularjs_Curl - Fatal编程技术网

Javascript Angular:将curl转换为Angular$http POST请求

Javascript Angular:将curl转换为Angular$http POST请求,javascript,ajax,angularjs,curl,Javascript,Ajax,Angularjs,Curl,我有一条卷曲线: curl -X POST -H "content-type: application/json" -H "AUTH_TOKEN: vLC4grMuKbtbamJL3L6x" localhost:8080/v1/segments?appkey=c2439fb30a1cad03e9e02bd733ef2ad5 -d '{"segment" : {"segment_name" : "ャロットケーキが好き", "segment_type":"static"}}' 现在,curl直接命

我有一条卷曲线:

curl -X POST -H "content-type: application/json" -H "AUTH_TOKEN: vLC4grMuKbtbamJL3L6x" localhost:8080/v1/segments?appkey=c2439fb30a1cad03e9e02bd733ef2ad5 -d '{"segment" : {"segment_name" : "ャロットケーキが好き", "segment_type":"static"}}'
现在,curl直接命中API。我希望能够在保存并重定向回路由“return region.”$save((function(){')之后执行$http POST:

} ]))

您知道如何在$http POST中正确格式化它吗?特别是,我是否需要将成功和错误重构为$http代码?即,成功重定向返回$location.path(“/”)或

我想是这样的,但不确定如何完成:

$http({
method: 'POST',
url: '',
data: '',
headers: {'Content-Type': 'application/JSON'}
}))

虽然我在这里阅读Angular doc:$http#post,但我仍然有点困惑,不知道如何用$http post直接命中这个卷曲


谢谢你的帮助

你在寻求帮助,这里有一些。我不确定我是否理解你在成功的情况下想要做什么,但为了结束,你可以从

$http({
        url: 'localhost:8080/v1/segments?appkey=c2439fb30a1cad03e9e02bd733ef2ad5',
        method: 'POST',
        data: {'segment' : {'segment_name' : 'ャロットケーキが好き', "segment_type":"static"}},
        headers: {'Content-Type': 'application/json', 'Auth_Token': 'vLC4grMuKbtbamJL3L6x'}
}).success(function (data, status, headers, config) {
            //handle success
            $location.path('/'); //maybe you want to do this  
}).error(function (data, status, headers, config) {
            //handle error
});
$http({
        url: 'localhost:8080/v1/segments?appkey=c2439fb30a1cad03e9e02bd733ef2ad5',
        method: 'POST',
        data: {'segment' : {'segment_name' : 'ャロットケーキが好き', "segment_type":"static"}},
        headers: {'Content-Type': 'application/json', 'Auth_Token': 'vLC4grMuKbtbamJL3L6x'}
}).success(function (data, status, headers, config) {
            //handle success
            $location.path('/'); //maybe you want to do this  
}).error(function (data, status, headers, config) {
            //handle error
});