van_folmert van_folmert - 4 months ago 20
Javascript Question

403 Access Forbidden when directly accessing a page using base_url()

I'm getting a 403 error when trying to access a page via

XHR
:

$("form").submit(function( event ) {
xmlhttp.open("GET","<?=base_url('application/views/pages/search_sql.php'); ?>",true);
xmlhttp.send();

event.preventDefault();
});


I could load the page
search_sql.php
by straightforward
xmlhttp.open("GET","search_sql",true);
but then it doesn't load the script directly - instead it is handled by controller and loaded with other views which are unwanted in this case.

Answer Source

You are using CodeIgniter so why are you trying to load anything directly?

Call the page as you would normally and add a controller method to do what is required in this situation. So:

Assuming you have a controller called 'Search' create a method called something relevant lets say 'special_case' and call that with any parameters it requires like so

<?php

class Search extends Controller {

    function index()
    {
        // I assume this is what it is currently doing
    }

    function special_case()
    {
        // Make this do whatever is required in this case.
    }

Then call it from your Javascript using the standard CodeIgniter controller/method/param1/param2 ...... mechanism.