1

This issue really takes too long to fix and its getting sick...

Yesterday started to appear a really annoying bug which i cant fix its roots to why it happens...

When i use the following javascript code:

$(".reply_to_article").click(function(){
    var cct = $.cookie('csrf_cookie_name');

    var body = $(this).parent().find("textarea");

    $.ajax({
        type: "POST",
        url: "http://www.domain.com/articles/replyToArticle",
        dataType: 'json',
        data: {
            body : body.val(),
            csrf_name : csrf_value
        },
        success: function(data) {

        }
    });
});

and click the reply_to_article button the request simply doesnt end and goes for unlimited time... when i check firebug the loading image always spins without ending... when i press ESC it doesnt return anything... also checked on all other browsers...

Also tried direct-access the ajax file and it works... but this POST doesnt

How can it works with GET but not POST?

stergosz
  • 5,754
  • 13
  • 62
  • 133
  • which browser did GET work on and also can you show the code for get, do you just change POST to GET? – Baz1nga Jun 27 '12 at 05:46
  • it worked on firefox,chrome,safari as im on a mac and yes i changed POST with GET – stergosz Jun 27 '12 at 05:46
  • Are you trying to communicate with another domain or is this on the same site? if you control the site can you post your server side code? – Baz1nga Jun 27 '12 at 05:47
  • Is it a server-side problem? Does the server not respond to POST requests properly? Try using something like RESTClient in Firefox to see how the server responds to various requests. – David Jun 27 '12 at 05:48
  • @Baz1nga no its the same site... it was working before 2 days but now its not... and i cant find the reason – stergosz Jun 27 '12 at 05:48
  • @David Some requests work but others dont... also some requests work on some pages and others not... this is another weird thing that happens... – stergosz Jun 27 '12 at 05:49
  • You could try using $.POST and see if that works. You can also delete your success function. – Robert Jun 27 '12 at 06:05
  • sounds like a cross domain issue. Can you try making the path relative to root ex: /foo/bar rather than http://www.xyx.com/foo/bar? – John Culviner Jun 27 '12 at 06:07
  • @Robert will try the $.POST, i have stuff in the success function so its needed – stergosz Jun 27 '12 at 06:09
  • @JohnCulviner i have other requests that work as they are now and my above js code was working the past days/months how its that the problem now? – stergosz Jun 27 '12 at 06:10
  • @fxuer... All the other people are talking about all this complicated things. But sometimes...I just find the .ajax too much writing and simplify it with .post. Then it miraculously works. Probably a type originally haha. – Robert Jun 27 '12 at 06:19
  • @Robert just tried it... as i guessed i dont get a response back and the loading picture on firebug keeps spinning – stergosz Jun 27 '12 at 06:24
  • @Robert $.POST internally calls $.ajax i.e its nothing but a wrapper around $.ajax – Baz1nga Jun 27 '12 at 06:26
  • @Baz1nga I know that but I was just ruling out the small factor that OP might have a little typo somewhere. – Robert Jun 27 '12 at 06:41
  • it seems that it works on Safari but not on firefox,chrome... – stergosz Jun 27 '12 at 08:31

1 Answers1

0

I am guessing you have CSRF security on and you are "POST"ing data to the controller. The controller in this case calls the Security constructor which checks & verifies the CSRF token. If the token is not correct, then it returns a 500 HTTP error. Thus first check for 500 error. if thats the case I am guessing the way you are handling csrf token is incorrect currently.

I am not sure what csrf_name and csrf_value is but it should be

The name should be: <?php echo $this->security->get_csrf_token_name();?> and the value should be <?php echo $this->security->get_csrf_hash(); ?>

store both these values in a hidden field and then use it in your script.

Read this SO question for details: codeigniter csrf protection error with ajax

Community
  • 1
  • 1
Baz1nga
  • 15,485
  • 3
  • 35
  • 61
  • Why i cant see that i get a 500 Error? also no errors on error_log? I use the correct csrf token name and value so there isnt a problem there as well... – stergosz Jun 27 '12 at 06:15