0

I have error in here when i'm trying to update data using slim as API and angular as Client.

My slim codes :

<?php

$app->put("/update/:id",function($id)use($app){

    $body = $app->request->getBody();
    $user = json_decode($body);

    $newData = Users::find($id);
    $newData->username = $user->username;
    $newData->first_name = $user->first_name;
    $newData->last_name = $user->last_name;
    $newData->address = $user->address;
    echo $newData->save();
});

And my update angular codes :

app.controller('editUserController',function($scope, $http, $location, $routeParams){
    var id = $routeParams.id;
    $http.get('http://address.com/slimApi/index.php/cekOne/'+ id).success(function(response){
        $scope.users = response;
    });

    $scope.updateUser = function()
    {
        var r = confirm('Are you sure??');
        if (r==true) {
            $http.put('http://address.com/slimApi/index.php/update/' + id, $scope.users).success(function(response){
                $scope.users = '';
                $location.path('/');
            });
        } else{};
    }
});
alexw
  • 8,468
  • 6
  • 54
  • 86
jonsnow
  • 9
  • 1
  • 1
    Any chance your web page is loaded file a `file://` URL rather than an `http://` URL? – jfriend00 Apr 26 '16 at 05:01
  • are you opening your html directly or you are opening using server? – Divyesh Savaliya Apr 26 '16 at 05:05
  • @jfriend00 : sorry, what do you mean ? – jonsnow Apr 26 '16 at 05:25
  • @DivyeshSavaliya : i'm using server – jonsnow Apr 26 '16 at 05:25
  • @sandiramadhan99 - Look in the URL bar. What is the URL to the web page. Does it start with `http://`? And, please don't disappear for 20 minutes after you post. It makes it really hard for us to engage and ask you clarifying questions. Your best chance for people to see your question is in the first 30 minutes. If you aren't around and your question isn't perfectly clear, you miss much of your opportunity to find someone who can help. Plus those of us who do engage and ask clarifying questions just get frustrated and leave. – jfriend00 Apr 26 '16 at 05:25
  • @jfriend00 it using http://, sorry before that – jonsnow Apr 26 '16 at 05:27
  • 1
    That error usually comes from a file:// URL or some non-standard protocol at the front of a URL used somewhere in your app. See http://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local – jfriend00 Apr 26 '16 at 05:28
  • @jfriend00 wait a minutes – jonsnow Apr 26 '16 at 05:32
  • @jfriend00 i still confused :( i'm newbie here.. – jonsnow Apr 26 '16 at 05:39
  • @jfriend00 i still confused :( i'm newbie here.. – jonsnow Apr 26 '16 at 05:40

0 Answers0