Welcome Guest, Not a member yet? Register   Sign In
URIs from Ajax
#1

Brand new to CodeIgniter and looking forward to converting my existing website to it.  I've been through the "first application" section of the user guide and have a good handle on the general architecture.

My current application has a lot of jquery code, mostly to handle the submission of forms for adding/editing database data.  Currently the urls in my Ajax calls are relative, for example "pleasedothis.php".  I have separate environments for dev, test, and live so doing it this way always resolves to the correct base url based on where the server is running.  

My question is, will the same technique work with CI?  For example, if I send the Ajax request to "pleasedothis/list" with no base url, will CI recognize it and route it correctly.

Thanks,
Pete
Reply
#2

No it wont.

You need to tell it were to go controller/method

Code:
// like this
url: "<?= base_url('controller/method');?>",

// or like this
// HTML HEAD
<head>
    <script type="text/javascript">
        //<![CDATA[
        baseUrl = '<?= base_url();?>';
        //]]>
    </script>

</head>

url: baseUrl+'controller/method',

SEECodeIgniter 4 Ajax Form Submit Validation Example
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

OK Thanks.  Sounds like the same as using window.location.origin in javascript and including that in the URI
Reply




Theme © iAndrew 2016 - Forum software by © MyBB