0

I'm trying to make an AJAX call in Vue to a PHP script, but it doesn't seem to be working.

Vue:

methods: {
  onSubmit () {
    if (this.valid) {
      this.$http.post('http://remindwordserver.loc/register.php', {test: 'test'}).then(response => {
        console.log(response.body)
      }, response => {})
    }
  }
},

PHP:

`<?php

print_r($_POST);` 

$_POST is empty

What am I doing wrong?

Venantius
  • 2,471
  • 2
  • 28
  • 36

1 Answers1

0

I'm not too familiar with PHP, but I'll give it a go.

The $_POST variable only contains data from the request when the HTML Content-Type of the request is application/x-www-form-urlencoded or multipart/form-data. vue-resource by default sets the Content-Type of the request to application/json.

If you want to access JSON data in your PHP script, you'll have to decode the request data from JSON. See Receive JSON POST with PHP.

Decade Moon
  • 32,968
  • 8
  • 81
  • 101