Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70612

How to post values from ionic to codeigniter rest api

$
0
0

@asha4640 wrote:

My ts file function is

save() {
var link = ‘http://localhost/apicode/index.php/Login/addUser’;
var myData = JSON.stringify({name:this.registerForm.value.name,username: this.registerForm.value.username,password:this.registerForm.value.username});
console.log(myData);
this.http.post(link, myData)
.subscribe(data => {
this.data.response = data["_body"];
console.log(“success!”);
this.navCtrl.navigateForward(’/login’);
}, error => {
console.log(“Oooops!”);
});
}

this codeigniter controller function

function addUser_post(){

    $_POST = json_decode(file_get_contents('php://input'), true);
$postdata = $this->input->post();

     if(!$postData ){

            $this->response("Enter complete user information to save", 400);

     }else{

        $result = $this->login_model->add($postData);

        if($result === 0){

            $this->response("Userinformation coild not be saved. Try again.", 404);

        }else{

            $this->response("success", 200);  
       
        }

    }

}

It shows the error when i call the save function

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70612

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>