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

#1

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 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”, 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

#2

Your post is unreadable - did you look at it?

What is your ionic info output?

#3

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

#4

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

Please also spend some time to format your post.

#5

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 Observables here, not raw scalars.

#6

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.

#7

ok thank you so much. i just did

#8

Still no ionic info output in sight.

#9

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

1 Like
#10

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

#11

ok please check now again

#12

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?

#13

yes, i’m using postman.

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

#14

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

#15

ok thank you so much

#16

yes i know i will put a picture to show you

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

    $this->response($data);

}

#17

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

#18

yes it is the devtool postman

#19

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)

#20

ok i’m sorry.

this is my php code function:

public function prueba_post() {
$data = $this->post();

    $this->response($data);

}