Postios server does not receive data from browser

I am using axios.post, but the server does not seem to receive post data.

This is what I have:

var baseURL = "http://localhost:8888/dbRouting.php";
var body = {
  function: 'foo',
  id: 'bar',
}

axios.post(baseURL, body)
.then((response) => { console.log( "Data Loaded AXIOS: " + response.data ); })
.catch(function (error) {console.log(error);});

// Data Loaded AXIOS: array(0) {
// }

This jQuery entry in the same file, on the other hand, works:

$.post( baseURL, body )
  .done(function( data ) {
     console.log( "Data Loaded JQUERY: " + data );
  });

//Data Loaded JQUERY: array(2) {
//["function"]=>
//string(3) "foo"
//["id"]=>
//string(3) "bar"
//}

The server file (dbRouting.php) is simple:

<?php
var_dump($_POST);
?>

Any ideas what could happen?

+4
source share
2 answers

This is my way to enable the back-end that php processes through $ _POST. This is part of my code in the vue section inside the method.

Assuming you send it to post_url and you have an object, var myObject:

var myObject = {
  property: value,
  property1: value1,
  property2: value2
}

Inside my vue method section:

 updateForm: function( myObject ){
            var post_url = (your post url);

            axios.post(post_url, makePostReady( myObject ) )
            .then(function (response) {
                console.log(response);
             })
            .catch(function (error) {
                console.log(error);
             });
      }

( acios post) . , , , axios,

property=value&poperty1=value1&property2=value2......

:

function makePostReady( object )
{
    var sentence = "";
    for (var key in object) {
        sentenceAdd = key + '=' + object[key] + '&';
        sentence = sentence + sentenceAdd;
    }
    //console.log( 'sentence: ' + sentence );
    return sentence;
}

var_dump ($ _POST) post_url , . .

,

,

enter image description here

enter image description here

+1

, . URL- localhost: 8888/dbRouting.php JQuery Axios. ? .catch ? ? localhost: 8888?

(, Postman https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en)

0

Source: https://habr.com/ru/post/1670193/


All Articles