# What I try to do is send data to php using codeigniter and receive a response from the server to manage a login

**URL:** <https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318>\
**Category:** ionic-v3\
**Created:** [August 3, 2018, 7:27pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318 "2018-08-03T19:27:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 7:27pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/1 "2018-08-03T19:27:03Z")

</div>

What I try to do is send data to php using codeigniter and receive a response from the server to manage a login.

in a few words send an email and a password to php using URLSearchParams in the service part

my login method:

login( email:string, pass:string ){

```
// console.log(email, pass);

let data = new URLSearchParams();
data.append('correo', email);
data.append('contrasena', pass);

// console.log(data);

let url = 'http://localhost:90/generales/rest/index.php/login/prueba';

return this.http.post( url, data ).map( resp=>{

  let data_resp = resp;
  console.log(data_resp);
        
});

```

}

when i’m trying this i have this error

POST [http://localhost:90/generales/rest/index.php/login/prueba](http://localhost:90/generales/rest/index.php/login/prueba) 404 (Not Found)  
core.js:1449 ERROR HttpErrorResponse {headers: HttpHeaders, status: 404, statusText: “Not Found”, url: “[http://localhost:90/generales/rest/index.php/login/prueba](http://localhost:90/generales/rest/index.php/login/prueba)”, ok: false, …}  
defaultErrorLogger @ core.js:1449  
ErrorHandler.handleError @ core.js:1510  
IonicErrorHandler.handleError @ ionic-error-handler.js:61  
next @ core.js:5508  
schedulerFn @ core.js:4342  
SafeSubscriber.\_\_tryOrUnsub @ Subscriber.js:242  
SafeSubscriber.next @ Subscriber.js:189  
Subscriber.\_next @ Subscriber.js:129  
Subscriber.next @ Subscriber.js:93  
Subject.next @ Subject.js:55  
EventEmitter.emit @ core.js:4322  
(anonymous) @ core.js:4782  
t.invoke @ polyfills.js:3  
r.run @ polyfills.js:3  
NgZone.runOutsideAngular @ core.js:4708  
onHandleError @ core.js:4782  
t.handleError @ polyfills.js:3  
r.runTask @ polyfills.js:3  
e.invokeTask @ polyfills.js:3  
p @ polyfills.js:2  
v @ polyfills.js:2  
error (async)  
O @ polyfills.js:2  
t.scheduleTask @ polyfills.js:3  
onScheduleTask @ polyfills.js:3  
t.scheduleTask @ polyfills.js:3  
r.scheduleTask @ polyfills.js:3  
r.scheduleEventTask @ polyfills.js:3  
(anonymous) @ polyfills.js:2  
(anonymous) @ http.js:2353  
Observable.\_trySubscribe @ Observable.js:172  
Observable.subscribe @ Observable.js:160  
subscribeToResult @ subscribeToResult.js:23  
MergeMapSubscriber.\_innerSub @ mergeMap.js:132  
MergeMapSubscriber.\_tryNext @ mergeMap.js:129  
MergeMapSubscriber.\_next @ mergeMap.js:112  
Subscriber.next @ Subscriber.js:93  
ScalarObservable.\_subscribe @ ScalarObservable.js:49  
Observable.\_trySubscribe @ Observable.js:172  
Observable.subscribe @ Observable.js:160  
MergeMapOperator.call @ mergeMap.js:87  
Observable.subscribe @ Observable.js:157  
FilterOperator.call @ filter.js:60  
Observable.subscribe @ Observable.js:157  
MapOperator.call @ map.js:56  
Observable.subscribe @ Observable.js:157  
MapOperator.call @ map.js:56  
Observable.subscribe @ Observable.js:157  
webpackJsonp.289.LoginPage.ingresarDB @ login.ts:29  
(anonymous) @ LoginPage.html:31  
handleEvent @ core.js:13589  
callWithDebugContext @ core.js:15098  
debugHandleEvent @ core.js:14685  
dispatchEvent @ core.js:10004  
(anonymous) @ core.js:10629  
(anonymous) @ platform-browser.js:2628  
t.invokeTask @ polyfills.js:3  
onInvokeTask @ core.js:4751  
t.invokeTask @ polyfills.js:3  
r.runTask @ polyfills.js:3  
e.invokeTask @ polyfills.js:3  
p @ polyfills.js:2  
v @ polyfills.js:2

this look like headers need to be setup but i did by my server with:  
Header(“Access-Control-Allow-Headers”, “\*”);  
Header(“Access-Control-Allow-Methods: PUT, GET, POST, DELETE, OPTIONS”);  
Header(“Access-Control-Allow-Headers: Content-Type, Content-Length, Accept-Encoding”);

my ionic info:

Ionic:

ionic (Ionic CLI) : 4.0.3 (C:\Users\fulano\AppData\Roaming\npm\node\_modules\ionic)  
Ionic Framework : ionic-angular 3.9.2  
@ionic/app-scripts : 3.1.11

Cordova:

cordova (Cordova CLI) : 8.0.0  
Cordova Platforms : none

System:

NodeJS : v8.11.3 (C:\Program Files\nodejs\node.exe)  
npm : 6.2.0  
OS : Windows 10

Environment:

ANDROID\_HOME : not set

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [August 3, 2018, 8:45pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/2 "2018-08-03T20:45:08Z")

</div>

Your post is unreadable - did you look at it?

What is your `ionic info` output?

---

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 9:27pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/3 "2018-08-03T21:27:46Z")

</div>

What I try to do is send data to php using codeigniter and receive a response from the server to manage a login.

in a few words send an email and a password to php by email using URLSearchParams in the service part

my ionic version  
ionic@4.0.3

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [August 3, 2018, 9:28pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/4 "2018-08-03T21:28:30Z")

</div>

> [@santanajensy](#):
>
> my ionic version  
> ionic@4.0.3

Not what I asked for. Run `ionic info` in your project directory.

Please also spend some time to format your post.

---

<div class="post-metadata">

**Author:** ![rapropos](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/rapropos/32/100227_2.png) [@rapropos](https://forum.ionicframework.com/u/rapropos)\
**Post date:** [August 3, 2018, 9:35pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/5 "2018-08-03T21:35:11Z")

</div>

You are badly abusing the `map` operator. It is designed solely for transforming data from format A to format B. None of the error-handling, view layer stuff, or state modification (assigning to object properties) should be in there. I would even argue error-handling and alert popping doesn’t belong in your service class at all, but at the very least you need to get it out of `map` and into `tap`, if you insist on storing state in the provider.

The way you are storing that state is also problematic, because clients have no way of (a) knowing when it is valid or (b) being informed of changes. You should be exposing `Observable`s here, not raw scalars.

---

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 9:57pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/6 "2018-08-03T21:57:42Z")

</div>

ok i really understand that now but i’m new using ionic. pls may you write me an example or please edit my code. i will appreciate that.

---

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 9:58pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/7 "2018-08-03T21:58:41Z")

</div>

ok thank you so much. i just did

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [August 3, 2018, 10:02pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/8 "2018-08-03T22:02:16Z")

</div>

> [@santanajensy](#):
>
> ok thank you so much. i just did

Still no `ionic info` output in sight.

---

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 10:04pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/9 "2018-08-03T22:04:15Z")

</div>

Ionic:

ionic (Ionic CLI) : 4.0.3 (C:\Users\fulano\AppData\Roaming\npm\node\_modules\ionic)  
Ionic Framework : ionic-angular 3.9.2  
@ionic/app-scripts : 3.1.11

Cordova:

cordova (Cordova CLI) : 8.0.0  
Cordova Platforms : none

System:

NodeJS : v8.11.3 (C:\Program Files\nodejs\node.exe)  
npm : 6.2.0  
OS : Windows 10

Environment:

ANDROID\_HOME : not set

---

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 10:16pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/10 "2018-08-03T22:16:13Z")

</div>

ionic (Ionic CLI) : 4.0.3 (C:\Users\fulano\AppData\Roaming\npm\node\_modules\ionic)  
Ionic Framework : ionic-angular 3.9.2  
@ionic/app-scripts : 3.1.11

Cordova:

cordova (Cordova CLI) : 8.0.0  
Cordova Platforms : none

System:

NodeJS : v8.11.3 (C:\Program Files\nodejs\node.exe)  
npm : 6.2.0  
OS : Windows 10

Environment:

ANDROID\_HOME : not set

---

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 10:16pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/11 "2018-08-03T22:16:58Z")

</div>

ok please check now again

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [August 3, 2018, 10:22pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/12 "2018-08-03T22:22:56Z")

</div>

> [@santanajensy](#):
>
> POST [http://localhost:90/generales/rest/index.php/login/prueba](http://localhost:90/generales/rest/index.php/login/prueba) 404 (Not Found)

Seems your server is returning an error 404 when you POSt to this URL.  
Can you manually POST there using a tool like Postman or Insomnia?

---

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 10:53pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/13 "2018-08-03T22:53:56Z")

</div>

yes, i’m using postman.

postman can see everything but when i’m use my service is the problem.

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [August 3, 2018, 11:00pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/14 "2018-08-03T23:00:50Z")

</div>

That doesn’t make sense. If the requests are identical, they have to be responded in the same way as well.

---

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 11:10pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/15 "2018-08-03T23:10:56Z")

</div>

ok thank you so much

---

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 11:20pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/16 "2018-08-03T23:20:46Z")

</div>

yes i know i will put a picture to show you

php code:  
public function prueba\_post() {  
$data = $this-\>post();

```
    $this->response($data);

}

```

 ![Screenshot%20(16)](https://global.discourse-cdn.com/ionicframework/original/3X/3/1/315bdfc2712136714871cee849154b46c1e4bb81.png)

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [August 3, 2018, 11:26pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/17 "2018-08-03T23:26:46Z")

</div>

And the request your app is creating, screenshot of the dev tools of your browser with the relevant tabs selected?

---

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 11:39pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/18 "2018-08-03T23:39:30Z")

</div>

yes it is the devtool postman

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [August 3, 2018, 11:41pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/19 "2018-08-03T23:41:45Z")

</div>

You didn’t understand what I said.

We need to see the request your app is sending and results in a 404. We have to be able to compare. (Actual request, not the code that generates the request)

---

<div class="post-metadata">

**Author:** ![santanajensy](https://avatars.discourse-cdn.com/v4/letter/s/eb9ed0/32.png) [@santanajensy](https://forum.ionicframework.com/u/santanajensy)\
**Post date:** [August 3, 2018, 11:45pm UTC](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318/20 "2018-08-03T23:45:13Z")

</div>

ok i’m sorry.

this is my php code function:

public function prueba\_post() {  
$data = $this-\>post();

```
    $this->response($data);

}

```

 ![Screenshot%20(15)](https://global.discourse-cdn.com/ionicframework/original/3X/5/e/5e557f53433b5f4b69474f5997fdcac2e64c47dc.png)

[Next page](https://forum.ionicframework.com/t/what-i-try-to-do-is-send-data-to-php-using-codeigniter-and-receive-a-response-from-the-server-to-manage-a-login/137318.md?page=2)
