Codeigniter: AJAX fails to access the controller: Access-Control-Allow-Origin

So I was trying my hands first time on Codeigniter. I tried to build a login system. Have a look here:

When you try to log in, it is supposed to use AJAX to send data to a controller but the chrome displays an error:

XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '' is therefore not allowed access. The response had HTTP status code 500.

I searched for the issue and found it has something to do with Cross-Domain stuff. I did not try the remedies since I think that I aint using AJAX from another domain. The controller and the view/jQuery are present on the same domain.

Is it something because I have installed Codeigniter in a sub folder on my domain i.e Udemy! I would like to state that I edited the base url correctly to in my config.php

Set a header

Maybe have problems with different ports,. It doesn't matter that they are on the same machine/hostname.

www vs no www is considered different subdomain and therefore different origin.

Use a relative url