Help with Web services/PHP


#1

Someone please help - I am a beginner in Ionic, I have created some basic apps, but would like to use some sort of call to a PHP page to send and return data. Can someone please guide me where to go to learn about this? I have looked for some examples, but I find only code for the App side, nothing on a basic example on the PHP side. I have a PHP server that connects to an Oracle database, and would like to create a function that will process the data. Please advise or add a good link to a site that can teach me. thanks!


#2

Please use $http.post or $http.get .

For example to use post, here is the sample snippet, Please note that the link should be hosted in some live domain, Locally hosted link didn’t work for me

var link = 'http://test.com/Login.php';
			
$http.post(link, {username : $scope.username,password: $scope.password}).then(function (res){
				var response_data = JSON.parse(JSON.stringify(res.data));
				if(response_data['result'] == "success"){
					
					// you logic here
					
					function success(value){
						console.log(value);
					}
					function fail(){
						console.log("fail");
					}
					// redirect to controller
					$state.go('enquiries');
				}else{
					
					var alertPopup = $ionicPopup.alert({
					title: 'Login failed!',
					template: response_data['error']
					});
				}
			});

#3

surajde16,

Thank you for your time and effort, but what you posted was the Ionic code for the App side. I can find many examples of the Ionic code, but I cannot find any examples of the PHP side. What I need help with is coding the login.php from your example. I have access to a live domain, but my code is not working. Could you please show a quick example of PHP that sends data to the Ionic app?