POST 데이터 전달 지난 이틀 동안 $ http를 사용하여 CodeIgniter 나머지 API에 이오닉 응용 프로그램의 데이터를 게시하려고합니다. 하지만 내 게시물 데이터가 비어 있습니다. 나는 어떤 링크를 심판한다. 그러나 침묵하지 못했습니다. 아래는 제 코드입니다.이온 프레임 워크에서 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 이름을} –
$ http ({ 메서드 : "POST", URL : "http : //localhost/vas_api/index.php/api/User/index/", 데이터 : {이름 : 사용자 이름} }). (함수 mySucces (응답) { console.log (응답) }); 위와 같은 형식을 사용해야합니다. –
@Sathosh 제 답변을 아래에서 살펴 보시기 바랍니다. 또한 작동하지 않는 경우 알려주십시오. –