我需要帮助使用angularjs提交POST请求,因为我一直收到错误回调-1(并且发送的数据总是为null,除非我查看response.config.data)。我尝试使用速记/ longhand,urlencoded和application / json都无济于事。
以下是我用于longhand / url编码尝试的代码:
// data to send to muscle
var content = {
email: "...",
title: "...",
format: "...",
tree: "...",
order: "...",
sequence: data.join()
};
$http({
method: 'POST',
url: 'http://www.ebi.ac.uk/Tools/services/rest/muscle/run/',
data: content,
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8'
},
transformRequest: [function(data) {
return angular.isObject(data) && String(data) !== '[object File]' ? $httpParamSerializer(data) : data;
}]
}).then (function successCallback(response) {
console.log("SUCCESS");
}, function errorCallback(response) {
console.log("ERROR");
console.log(response);
console.log(response.headers);
console.log(response.config);
});
以下是我用于速记/ json尝试的代码
// submit post to MUSCLE
$http.post('http://www.ebi.ac.uk/Tools/services/rest/muscle/run/', content).then(function (success) { ....
以下是我在两种情况下收到的错误:
Object { data: null, status: -1, headers: fd/<(), config: Object, statusText: "" }
Object { method: "POST", transformRequest: Array[1], transformResponse: Array[1], paramSerializer: nf/this.$get/<(), url: "http://www.ebi.ac.uk/Tools/services…", data: Object, headers: Object }
以下是我用来提交POST(运行请求)的参考website
任何帮助将不胜感激,谢谢!