Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] csrf & jqueryui autocomplete
#1

[eluser]predat0r[/eluser]
Hi,
I use JQueryUI Autocomplete on my page for search purposes. If I include the csrf cookie data to the ajax call, it doesn't pass the typed parameter, only the csrf data. I don't know much about JQuery but maybe someone saw similar problem during CI development..

CSRF switched OFF - Firebug console says: (and term "asus" passed to the php script well)

term = asus

CSRF switched ON:

[object Object]
csrf_test_name 23d8bf447d1d3d8825d2080fd87f4475

So some way it don't takes the parameter to my php script.

The ajax code:
Code:
$(function() {
    $(".term").autocomplete({
            source: function(req, add){
                    var cct = $.cookie('csrf_test_name');
                    param = '&csrf;_test_name='+cct;
                    console.log(req+param);
                    $.ajax({
                        url:base_url+'shop/autocomplete',
                        dataType: 'json',
                        type: 'POST',
                        data: req+param,    
                        success: function(data){
                            if(data.response =='true'){
                               add(data.message);
                            }
                        }
                    });
            },
            minLength: 2,
            select: function(event, ui){
                $(this).end().val(ui.item.value);
            }
     });
});

Any idea? Thank you
#2

[eluser]InsiteFX[/eluser]
Read this article - Use jQuery cookie

InsiteFX
#3

[eluser]predat0r[/eluser]
Thanks, it works now.. i get a bit of code snippet hint from jq ui page, and modified the code:

data: { term : req.term, csrf_test_name : cct},

this way works the param giving, and bad with adding the params with '+' sign




Theme © iAndrew 2016 - Forum software by © MyBB