input post empty - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: input post empty (/showthread.php?tid=69208) |
input post empty - Valerekk - 10-19-2017 Hi guys, i'm writing a backend in CI (frontend separated in html/js) when i tried to send POST data to my controller $_POST is empty.. I've tried for few way but i always receive a empty array. Maybe the problem could be about htaccess??? tried to call my API Code: http://mysite.com/users/register_post_user id=test email=[email protected] tried already to set url with or without / at the end my controller - Users.php - PHP Code: public function register_post_user() Code: Array ( ) i'm sending request by Postman and my frontend. the result doesn't change. here my - .htacces - (modified only for removing index.php) Code: RewriteEngine on RE: input post empty - neuron - 10-19-2017 which js frawework you are using for posting? As I remember I had similar using when I used Angularjs. RE: input post empty - ponzo - 10-19-2017 Try PHP Code: $_POST = json_decode(file_get_contents("php://input"), true); Or if it's not json you're sending without the json_decode RE: input post empty - Valerekk - 10-20-2017 (10-19-2017, 11:21 PM)neuron Wrote: which js frawework you are using for posting? As I remember I had similar using when I used Angularjs. I tried by Jquery, pure Javascript and tool called Postman. RE: input post empty - Valerekk - 10-20-2017 (10-19-2017, 11:53 PM)ponzo Wrote: Try I'm sending two easy vars like => page.php?VAR1=value&VAR2=value2 I'm not sending json data RE: input post empty - Narf - 10-20-2017 You're showing how you check if the vars were received, but not how you actually make the request. RE: input post empty - InsiteFX - 10-20-2017 We need to see your JavaScript code on how you are sending the data etc; RE: input post empty - Valerekk - 10-20-2017 my js function Code: function sendLogin(id, email) { the frontend is hosted in another space (app, localhost, another server) so i set the header in my controllers for accepting external request with PHP Code: header('Access-Control-Allow-Origin: *'); could be the .htaccess ? -------- UPDATE ----------- sending data by GET it works. example my request Code: http://mysite.com/users/register_post_user/?id=5890459084523908&email=testemail the result is Code: Array ( [id] => 5890459084523908 [email] => testemail ) tested by URL in browser directly and by Postman.... RE: input post empty - ivantcholakov - 10-20-2017 js: Code: function sendLogin(id, email) { PHP: Code: public function register_post_user() RE: input post empty - Valerekk - 10-21-2017 (10-20-2017, 09:24 AM)ivantcholakov Wrote: js: It works!!! thank you! |