0👍
Ajax no send the “types submit”. Change PHP code by next example to check this.
PHP
var_dump( $_POST );die();
The Form is a php array assoc, you remove json_decode.
- [Vuejs]-How to read json from local storage and display data in VUE
- [Vuejs]-Vue: Show image from Storage as Background
0👍
Here you go:
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
echo json_encode($_REQUEST); exit; // this is important!
}
But am not sure why your code didn’t work, the main problem with $_REQUEST is not so much that it has data from $_GET and $_POST, but also from $_COOKIE and they sometimes can override each other.
0👍
You can’t use the FormData object as is, because it implements iterator, you need to convert it to a object with key value pair data. Please try to change your code as follow:
JS:
var postData = {};
for(var entry of new FormData($("#submitalbum")[0]).entries()){
postData[entry[0]] = entry[1];
}
this.$http.post('http://localhost/musicdatabase/addalbum.php', postData)
.then(data => console.log(data.body));
UPDATE
You will have to remove your condition if($_POST['submit'])
or put an hidden field named submit to work.
Source:stackexchange.com