axios post params code example

Example 1: send axios request to php

<?php  
  $rp = json_decode(file_get_contents('php://input'), true);

Example 2: axios pass params

const axios = require('axios');

// Equivalent to `axios.get('https://httpbin.org/get?answer=42')`
const res = await axios.get('https://httpbin.org/get', { params: { answer: 42 } });

res.data.args; // { answer: 42 }

Example 3: axios post

axios.post('/user', {
    firstName: 'Fred',
    lastName: 'Flintstone'
  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

Example 4: how to send data in query param in axios in get request

const res = await axios.get('https://httpbin.org/get', { params: { answer: 42 } });

Example 5: include axios

<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

Example 6: axios post php

// JS
axios.post(url, JSON.stringify({
name: "this.name",
email: "this.psswrd"
}))
  
// PHP
$_POST = json_decode(array_keys($_POST)[0], true);

Tags:

Php Example