Welcome Guest, Not a member yet? Register   Sign In
Problems with ajax
#1

(This post was last modified: 07-29-2017, 07:06 AM by msheath. Edit Reason: code update )

My setup is Windows 10, Wamp version 3.0.6 and Codeigniter 3.0.6. I am trying to use the Calendar class to generate a calendar that will permit content updating by clicking on a particular date. I am following an old tutorial by Burak Guzel (https://www.youtube.com/watch?v=qMsEAtXtE2g) who uses ajax. The calendar appearance on the page seems correct. My jquery code, copying his (apart from the csrf elements), is:
Code:
    $('.calendar .day').click(function() {

        var name = '<?php echo $this->security->get_csrf_token_name(); ?>'
        var hash = '<?php echo $this->security->get_csrf_hash(); ?>'

        day_num = $(this).find('.day_num').html();
        day_data = prompt('Enter stuff', $(this).find('.content').html());
        if (day_data != null) {
            $.ajax({
                url: window.location,
                type: 'post',
                data: {
                    day: day_num,
                    data: day_data,
                    name: hash
                },
                success: function(msg) {
                    location.reload();
                }
            });
        }
    });

The prompt appears correctly when I click on a date and Firefox developer tools console shows the POST with the correct url but with a 403 Forbidden error. I'm guessing this is a csrf issue but when I try to test this by setting 'csrf_protection' to FALSE the console shows no POST taking place at all. I'm also wondering whether Codeigniter 3 which I am using differs significantly in this respect from the version he was using and so the ajax code syntax is wrong?

Can anyone suggest what might be going on?
Reply


Messages In This Thread
Problems with ajax - by msheath - 07-29-2017, 04:27 AM
RE: Problems with ajax - by skunkbad - 07-29-2017, 02:16 PM
RE: Problems with ajax - by msheath - 07-29-2017, 02:51 PM
RE: Problems with ajax - by skunkbad - 07-29-2017, 04:40 PM
RE: Problems with ajax - by msheath - 07-30-2017, 01:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB