Problems sending data to the Ionic database

Asked

Viewed 365 times

6

I made a web application, with Angularjs and PHP, here on my computer, where I registered users and emails in the database and works perfectly.

I’m trying to do the same with Ionic, but when I try to insert, register a user, the following message is displayed on the console:

http://localhost:8888/systems/systems_web/Ionic/crudAngular/www/php/save.php 500 (Internal Server Error)......Ionic.bundle.js:19341 POST

  • Does anyone know why this message?
  • What am I doing wrong?
  • 2

    Check the server logs, because error 500 happens there. It could be a syntax error in the code, or an issue with the values you’re posting (or failing to post).

  • How to access these logs, @bfavaretto? The server is local.

  • It depends on the server. But it’s easier for you to look at the request response in the "network" tab of Chrome tools. There should be a message.

  • All right, I’ll take a look at that. @bfavaretto, you’ve already developed some mobile app on Ionic?

  • No, I never developed with Ionic.

  • No warning appears in the network tab... But in the console, I click on the black arrow in the message notice posted and a lot of things appear: > (Anonymous Function) @ ionic.bundle.js:19341
sendReq @ ionic.bundle.js:19160
status. $get.serverRequest @ ionic.bundle.js:18872
processQueue @ Ionic.bundle.js:23394 (Anonymous Function) @Ionic.bundle.js:23410 Parent. $get.Scope. $Eval @Ionic.bundle.js:24673

  • In the network tab the HTTP request has to appear as soon as it is made. Clicking on it you can see the response. This which you have now shown is client-side, but your error is on the server.

  • Nothing @bfavaretto... HTTP request does not appear in the network tab. Have a look at my code: > https://github.com/GugaSevero/crudAngular-Ionic/tree/master/www

  • You need to check whether (1) your js is sending valid json in the request body, and (2) whether the 3 keys/fields you try to use in the code are available in this json.

  • @bfavaretto, I have a web application that does the same thing and works... I would have to do this conference on js and check if these 3 keys are correct?

  • You have to find a way to check what is being received by php.

  • Yeah, with angular, it’s hard to see what’s coming in php using Postman.

  • The problem is that you cannot access http://localhost:8888 within an app, you have to set your machine’s IP address, make your machine’s IP point to the localhost, or use a remote server. , to know the IP (in osx/linux: ifconfig, in window: ipconfig), set this in . htdocs

Show 8 more comments

2 answers

0

Fala Brother,

Of course the error is on the server, probably you are trying to get the data using the array $_POST, I’m sorry to inform you this won’t work, but don’t worry there’s something easy you can do,

before your code, on the server, put this:

$myData = json_decode(file_get_contents("php://input"),true);

$myData will have the array with the data of your request.

hug and hope it was helpful :-D

  • Friend, I am not the author of the post but I was intrigued by your reply. What would be the reason to overwrite the superglobal $_POST?

  • It is almost 4 years since I wrote this rs, A super global $_POST should not be rewritten. then the assignment should be made to another variable ;)

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.