Codeigniter and AJAX - Cross Server Scripting Issues |
[eluser]lanzd[/eluser]
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: Code: http://mywebsite.com/page/method 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: Code: http://mywebsite.com/page/method/destination-page/destination-method When I am really trying to get to: Code: http://mywebsite.com/destination-page/destination-method 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?
[eluser]lanzd[/eluser]
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. Code: $(document).ready(function(){ 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! |
Welcome Guest, Not a member yet? Register Sign In |