Could anyone tell me why the following statement does not send the post data to the designated url?
(谁能告诉我为什么以下声明不会将发布数据发送到指定的网址?)
The url is called but on the server when I print $_POST - I get an empty array. (当我打印$ _POST时,在服务器上调用url - 我得到一个空数组。)
If I print message in the console before adding it to the data - it shows the correct content. (如果我在将数据添加到数据之前在控制台中打印消息 - 它会显示正确的内容。)
$http.post('request-url', { 'message' : message });
I've also tried it with the data as string (with the same outcome):
(我也尝试将数据作为字符串(具有相同的结果):)
$http.post('request-url', "message=" + message);
It seem to be working when I use it in the following format:
(当我以下列格式使用它时,它似乎正在工作:)
$http({
method: 'POST',
url: 'request-url',
data: "message=" + message,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
});
but is there a way of doing it with the $http.post() - and do I always have to include the header in order for it to work?
(但有没有办法用$ http.post()来做 - 并且我总是必须包含标题才能使它工作?)
I believe that the above content type is specifying format of the sent data, but can I send it as javascript object? (我相信上面的内容类型是指定发送数据的格式,但我可以将其作为javascript对象发送吗?)
ask by Spencer Mark translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…