Start by updating to the latest version of Joomla - 3.9.20 - if you're able to first.
A number of changes regarding JControllerLegacy were made in Joomla 3.8 (see https://github.com/joomla/joomla-cms/pull/13683) and so that is certainly worth investigating first.
Next take a look at this post which relates to calling JController from CLI
It redirects to whatever is set in controller's $redirect property, normally using setRedirect() method.
As an example, redirects are commonly used in form controllers. When saving an item fails, you are usually redirected back to the form. And when saving succeeds, you are redirected to a list of items.
In Joomla when you call a controller's save() method (usually it is a FormController if it has a save() method) the controller's save() method calls the corresponding Model right away and the validate() and save() methods of that Model. Thus when you want to save something using a component's save() method it is better and more straightforward to call the ...
You can definitely delete rows from multiple tables in a single query, but Joomla doesn't offer a query-building technique to accommodate this.
If you absolutely demand that query builder methods must be used, then you'll need to conduct some "surgery" (which isn't very pretty) on the generated query before executing it -- see https://joomla....
Why don't you do it in 2 steps?
I would do something like the following code. As you can see I use name spacing (since Joomla 3.8), used quoteName the table + field names and added a try/catch block.
public function delete_codes()
$id = $this->input->getInt('id');
$query = $db->getQuery(true)
What you should do is include &format=json in your URL. This tells Joomla that you want a JSON response rather than HTML, and it won't run (subsequently) your template to produce all your page HTML.
The usual approach is to call
in your controller code (ie in submit()). This will cause Joomla to look for a display() function in a ...