Welcome Guest, Not a member yet? Register   Sign In
Codeigniter and AJAX - Cross Server Scripting Issues

I'm trying to use AJAX in my CI application and am running into some issues with my requests being flagged as Cross Server Scripting (CSS).

I have links which without Javascript enabled they will follow through the link and work fine. When I try to intercept the click event I am basing my AJAX request URL off of the href of the link.

After rendering the URL would be something like:

The issue with this is that my requests sometimes return a 500 not found error. Since this is only happening sometimes I believe this is due to being flagged as CSS.

If I omit the base_url() from my href then all of my requests would look like:

When I am really trying to get to:

I'm sure there is a simple way to by pass this, I'm just not aware of it. Everywhere I looked they seem to use one of either way or sometimes site_url() instead of base_url();

Can someone shed some insight on this?

I found something in my code which was causing the issue. So this issue was not due to CSS.

However I have had issues with it in the past and remember I had found this bit of code which uses the CSRF cookie CI automatically generates (if enabled). I do not remember where I found it so I cannot provide a link.

    $(function($) {

        // this bit needs to be loaded on every page where an ajax POST may happen
            data: {
                csrf_prot: $.cookie('csrf_prot')

That just has to be included on any page which may make a AJAX request and it should prevent any CSS issues.

Note: You need jQuery cookie in order for this to work: https://github.com/carhartl/jquery-cookie

Sorry for this journal of mine, I would have deleted the entire thread but did not see an option. If an admin sees this it can be deleted. Many Thanks!

Theme © iAndrew 2016 - Forum software by © MyBB