budiodank / notif-app

Create Notification App With Apache Cordova
0 stars 0 forks source link

How To POST Axios Vue js to PHP Native in Cordova #4

Open budiodank opened 4 years ago

budiodank commented 4 years ago
     let config = {
          headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/x-www-form-urlencoded'
          },
        }
      this.axios.post('http://localhost/include/tools.php?action=add', {
            name: this.name,
            address: this.address,
            lat: this.lat,
            lng: this.lng,
            description: this.description
        }, config)
        .then(function (response) {
            console.log(response.data);
            }
        })
        .catch(function (error) {
            console.log(error.response);
        });

If we use this method, it will definitely get an error 404 not found which means it can't find the file. Changing proxyTable in config/index.js also doesn't work. So that axios post can work, I use a docker to run a web server for php. And that works well. Okay, now we install the docker first.

  1. Create a folder for the docker mkdir projects cd projects
  2. Clone Laradock git clone https://github.com/Laradock/laradock.git
  3. After successful cloning, enter the Laradock folder. cd laradock
  4. Run container laradock docker-compose up -d nginx mysql phpmyadmin redis workspace
  5. Move your php folder to the projects folder along side with the laradock folder
  6. Open http://localhost and your laradock is ready

Note : If in the fourth step fails, it means your web server is in conflict with another web server that is running. Then, turn off the web server. sudo service nginx stop sudo service mysql stop

Until here, restart vue js with a different terminal. npm run dev Try running Vue again in the browser. Surely you will see the port that is run vue changed to localhost: 8081. Why is that? Because port 8080 is used phpmyadmin on the docker.