最後の2日間から、私のイオニアアプリから$ httpを使用してCodeIgniterレストAPIにデータを投稿しようとしています。しかし私の投稿データは空になります。私はいくつかのリンクを参照してください。しかし、それを断ることはできませんでした。以下は私のコードです。イオンフレームワークからPOSTデータをCodeIgniter Rest APIに渡す
マイイオンビュー
<div class="list">
<label class="item item-input item-md-label" placeholder="Username" highlight-color="balanced" type="text">
<input class="md-input" type="text" ng-model="user.name">
<span class="input-label">Username</span>
<div class="hightlight hightlight-calm"></div>
</label>
<label class="item item-input item-md-label" placeholder="Password" highlight-color="energized" type="password">
<input class="md-input" type="password" ng-model="user.password">
<span class="input-label">Password</span>
<div class="hightlight hightlight-calm"></div>
</label>
</div>
<div class="padding">
<button ng-click="doLogin(user)" class="button button-full button-assertive ink">Login</button>
</div>
イオンコントローラコード:
.controller('LoginCtrl', function($scope, $timeout, $stateParams, ionicMaterialInk, $http, baseUrl) {
$scope.$parent.clearFabs();
$timeout(function() {
$scope.$parent.hideHeader();
}, 0);
ionicMaterialInk.displayEffect();
$scope.doLogin = function(user) {
$http({
method : "POST",
url : "http://localhost/vas_api/index.php/api/User/index/"+user.name
}).then(function mySucces(response) {
console.log(response)
});
}
})
CodeIgniterのコントローラコード:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require APPPATH . '/libraries/REST_Controller.php';
use Restserver\Libraries\REST_Controller;
class User extends REST_Controller {
public function index_post() {
if(!$this->input->post('name')) {
$this->response(null, 400);
}
$data = array(
'name' => $this->input->post('name')
);
$id = $this->User_model->insertUser($this->input->post('name'));
if(!is_null($id)) {
$this->response(array('response' => $id), 200);
} else {
$this->response(array('response', 'Null values'), 400);
}
}
}
CodeIgniterのモデルコード:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class User_model extends CI_Model {
function insertUser($data) {
$this->db->insert('user',array('name' => $data));
$userId = $this->db->insert_id();
return $userId;
}
}
?>
この問題を解決するのを手伝ってください。 {名:user.name} `私は事前
を使用してください事前CodeIgniterのバージョンを使用しています –
$ http({ メソッド: "POST"、 URL: "http://localhost/vas_api/index.php/api/User/index/"、データ:{name:user.name} }) (関数mySucces(レスポンス){ console.log(レスポンス) });上記のようなフォーマットを使用する必要がありますか? –
@Sathosh下の私の答えを見てくださいまた、あなたのために働いていない場合は教えてください –