0

previously, i have a question here about posting data to the Restful service in php:

ionic restful authentication to POST and get data from php

now i have a weird bug. it is only occur on my hosted api. but when i change the url to my local,

http://localhost/my-serv/api/myrest/method

it is working, i get the alert showing my input data. but when i change it to my hosting url

http://my-domain.com/my-serv/api/myrest/method it does nothing.

this is all the things on my app:

var tapp = angular.module('tapp', ['ionic', 'ngCordova', 'restangular']);
var baseURL = 'http://localhost/my-serv/api/myrest/';
tapp.config(function($stateProvider, $urlRouterProvider, RestangularProvider){
$stateProvider
.state('tapp.test', {
    url: '/tester',
    views: {
       'tappMenu':{
    templateUrl: 'template/tester.html',
     }
   }
});
RestangularProvider.setBaseUrl(baseURL);
}

controller

tapp.controller('tCtrl', function($scope, $http, Restangular){
   var posted = Restangular.all('posted');
   $scope.inData = {};
   $scope.tester = function(){
     var posting = { name: $scope.inData.text };
     posted.post(posting).then(function(re){
     alert(re.values);
     }, function(o){
       alert(o);
     });
   };
});

html template

<ion-view title="TEST">
<ion-content ng-controller="tCtrl">
    <form ng-submit="tester()">
    <div class="list">
        <label class="item item-input">
            <input type="text" name="testing" ng-model="inData.text" placeholder="First Name">
        </label>
    </div>
    <button type="submit" class="button button-block button-royal">Submit</button>
    </form>
</ion-content>

php codeigniter rest server

<?php defined('BASEPATH') OR exit('No direct script access allowed');

require APPPATH.'/libraries/REST_Controller.php';

class Myrest extends REST_Controller
{
    public function __construct()
   {
      parent::__construct();
        //$this->methods['user_get']['limit'] = 500; //500 requests per hour per user/key
   }
   public function posted_post()
   {
     $ok = $this->post('name');

     $arr = array('values'=>$ok);
     $this->response($arr, 200);
   }
}
faiz
  • 123
  • 5
  • 16
  • When you say it is not working, what does it mean, you are getting an error or what is happening? Did you try tracking the request in Chrome I guess its F12 to see Network Sources and you can track request there. – Himanshu Bhardwaj Jan 07 '15 at 05:02
  • yes. its not working and i dont event get any error message. what i have is the alert if the .post was not successfull. – faiz Jan 07 '15 at 07:50
  • i just put it to be `alert(o)` since i dont know other way to display the error message – faiz Jan 07 '15 at 08:13
  • you should be getting a HTTP response code from server. That should help. If you are not able to connect to server at all, then its a completely different issue. – Himanshu Bhardwaj Jan 07 '15 at 13:58
  • i can connect to server. i get the alert `[Object Object]` on the unsuccessfull request. however. my `localhost` gives me a value `123123` from my input. bothe server an local have same version of file. – faiz Jan 08 '15 at 03:14

0 Answers0