![]() |
AJAX Post Request does not work - 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: AJAX Post Request does not work (/showthread.php?tid=81346) |
AJAX Post Request does not work - aimpark - 02-18-2022 Hey guys, I'm new here. I have used CI over the past 10 years and love it. Unfortunately, I'm not getting the hang with everything CI4. So, I have created a form and when I submit it with AJAX (POST), I am getting no result. After further examinations I have come to realize that no data is passed when I execute a Ajax-Request with the type POST. PHP Code: public function index() PHP Code: { PHP Code: $view["head_title"] = 'Login' . TITLE; PHP Code: $view["nav_title"] = TITLE; PHP Code: // $js = 'get("#loginBox", "/login/test2/", "");'; PHP Code: $js = 'var xhr = $.ajax({ PHP Code: url: "/login/test/", PHP Code: type: "POST", PHP Code: dataType: "html", PHP Code: // data: "&test=test", PHP Code: data: { name: "John", location: "Boston" }, PHP Code: success: function(result) { alert(result); }, PHP Code: error: function(result, status, error) { alert("result" + result + ", status" + status + ", error" + error); }, PHP Code: });'; PHP Code: $view["js"] = $this->BrainsHTML->js($js); PHP Code: $this->Output->get_views($view, array('login')); PHP Code: } The alert shows the following: 4c352b93ef0c5b27c340fe27f2db69c11Array ( ) Array ( ) get I have been on this for hours now and I am out of ideas. Please help me and let me know if you need more infos about the setup. From where I stand it should be pretty simple, as I have never had an issue with this code in CI3. Thanks, Alain RE: AJAX Post Request does not work - aimpark - 02-18-2022 I finally found the solution. The Rewrite directives in .htaccess were not set properly. Sorry about that. RE: AJAX Post Request does not work - captain-sensible - 02-18-2022 first question does it have to be ajax ? RE: AJAX Post Request does not work - InsiteFX - 02-19-2022 I always like to get my forms working first then switch them over to Ajax. |