Cannot POST data

I have created a small application in which i am posting just one field name district in database using php mysql - my app.js file has code -

angular.module(‘todo’, [‘ionic’])
.controller(‘TodoCtrl’, function($scope,$http) {
$scope.insertdata = function(){
} });

and index.html has

<-body ng-app=“todo” ng-controller=“TodoCtrl”>
<-input type=“text” ng-model=“district”/>
<-input type=“button” value=“submit” ng-click=“insertdata()”/>

and insert.php has:

$data = json_decode(file_get_contents(“php://input”));
$districtname = mysql_escape_string($data->district);
mysql_query(“Insert into districtapp (districtname) Values ('”.$districtname.“')”);

I have installed codova whitelist and added these lines :

<-access origin=“"/>
<-allow-navigation href="http://
/" />
<-allow-navigation href="https://
/" />
<-allow-navigation href="data:
” />

I run app by ionic serve and get :

Error : POST 404 Not Found

Can anyone please help me to solve this Posting issue?

8100 is usually the port where ionic server listens to.
I doubt that your PHP server is running on this port.

Hi thanks for reply - my php port number is 8080 !

OK so you now you must use full PHP url in your post

Url for php is localhost:8080 -

@gmarziou One more thing : If i use “http.get” rather than “” then this get finds file and shows all the file code

I think : This meta for Content Security Policy is not working fine -
meta http-equiv=“Content-Security-Policy” content=“default-src *; style-src ‘self’ ‘unsafe-inline’; script-src * ‘unsafe-inline’ ‘unsafe-eval’”>

<link href="lib/ionic/css/ionic.css" rel="stylesheet"

As : -> {“error”:“not_found”,“reason”:“no such route”}

and console shows :


Your HTTP server is probably badly configured.

What should i do now?

This is ionic serve, it can happen, if livereload works for you thne ther’s nothing to worry about.

what’s the solution for POST 404 Not found?

Make sure your phone can reach your HTTP server, open browser on phone and try to reach the URL of your PHP script:

  • If it works then use same URL in your code, if you get CORS error (not 404) make sure that CORS is correctly configured on both sides (app and server).
  • if it does not work, learn about proxies

i am not using phone browser - i am using system browser - php with localhost:8080 works fine and this is for app - why my system browser is not reaching HTTP server :’( - I am new to all this -

This is a test to validate connection, but OK do as you want.

Instead of insert.php in your app’s javascript use Since the server is missing from the http request the current domain and port will be used as the server address.


php is running on 8080 - if i place my insert.php file in xampp or wamp folder and use OR http://localhost:8080/insert.php - This works fine but its unable to connect mysql - Why is it and how can i solve this ?

That error looks like it is because the HTTP server is not configured to respond to cross origin resource requests (CORS)

The OPTIONS verb is being used as “pre-flight” request to ensure the server supports the operation you want to do.


I would check the return values in mysql_connect in the PHP side to see if the connection to the MYSQL server succeeded or not.

@waterishail Thank you for this great help ! :blush:
Apache running on port 80
MySQL running on port 3306
and ionic framework is running on

and i have to write this to post in insert.php file.

Can these different ports create problem after deploying application on android?