• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AJAX post returns 500 error

#1
Hi
I have tried to build an installer for my codeigniter application and after completing af small form for collecting the database information it should execute a method for setting everything up.
This function is located in the install controller and the method is called runci and takes no arguments.
Currently looks like this:
PHP Code:
$data = array(
                
'status' => 'OK',
                
'http_response' => 200,
                
'message' => 'JSON data recieved'
            
);
            return 
json_encode($data); 
My JS looks like this and is written in-line at the bottom of my view-file:
Code:
//AJAX call to submit and install
            $(document).ready(function(){
                var formdata = <?php print json_encode($_POST); ?>;
                console.log(formdata);
                try {
                    $.post('<?php print site_url(); ?>install/runci', formdata);
                }
                catch(e) {
                    console.log(e);
                }
            });
HTML output is correct, but after outputting the formdata to the console and then posting, I get this error back in the console:
Code:
POST http://ignitercms.khit.dev/install/runci 500 (Internal Server Error)
I know that something is wrong, but I cannot see what.

Only change from default CI 2.2.1 is that I have added wiredesignz HMVC Modular Extentions
Reply

#2
It could be because you are returning your json instead of echoing it out back to the browser during the ajax request?
Reply

#3
I have tried changing from return to echo and even to print, but still gives me same error in the console and nothing in CI log or php error log.
Reply

#4
I fixed the issue. Seems like it could not handle it via post, so changed it to run using get requests.
Code:
//AJAX call to submit and install
$(document).ready(function(){
     var formdata = <?php print json_encode($this->input->post(NULL, TRUE)); ?>;
     console.log(formdata);
     $.ajax({
         type: "GET",
         url: "<?php print site_url('install/runci'); ?>",
         data: formdata,
         success: function(msg) {
             console.log(msg);
         }
     });
});
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.