question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

POST request not sending data to php script

See original GitHub issue

Summary

I using the following axios in a vue script to send data to a php script. I not having any luck

Context

  • Environment: *e.g.: vue 2.5, chrome 65, Mac OS 10.13

Vue Script

``

url = ‘http://localhost/testVue/testVue.php’; new Vue({ el: ‘#app’, data: { name:‘’, psswrd:‘’ }, methods:{ login: function(){ axios.post(url, { name: “this.name”, email: “this.psswrd” }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); }); } } }); ``

PHP script

`` $data = $_POST;

var_dump($data); ``

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

7reactions
kcjobcommented, Apr 23, 2018

A solution to the issue is to use a formData object ``

methods:{
   login: function(){
   var` formdata = new `FormData();
   formdata.append('name', this.name);
   formdata.append('email', this.psswrd);
   axios.post(url, {
     name: "this.name",
     email: "this.psswrd"
    })
2reactions
samuelmattoscommented, Jul 19, 2018

Thanks, did i have same problems with PHP and twig. And solved implemented the function:

function getFormData($form) {
    var unindexed_array = $form.serializeArray();
    var formdata = new FormData();
    $.map(unindexed_array, function (n, i) {
        formdata.append(n['name'], n['value']);
    });
    return formdata;
}

var formData = getFormData($("#cad_evolucao"));
axios.post(url, formData);
Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - $.post not sending data to php script - Stack Overflow
$.post not sending data to php script · Look into the $.ajax() syntax. · check $_SERVER['REQUEST_METHOD'] . · Watch the request / response...
Read more >
Http.request not sending POST data? (SOLVED) - Defold Forum
I have validated my php file by sending an http request using this site. The POST data I send there does appear in...
Read more >
How do I send a POST request using PHP? - ReqBin
There are two options for sending POST requests from PHP: using the built-in Curl library and the CURL-less method that uses PHP's native ......
Read more >
HTTP Request with POST data not working - Questions - n8n
Your PHP script doesn't understand your request as Body Content Type: Raw/Custom doesn't send a Content-Type header. Unless you were to set one ......
Read more >
HTTP Methods GET vs POST - W3Schools
The POST Method · POST requests are never cached · POST requests do not remain in the browser history · POST requests cannot...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found