Problem jQuery in CI 2.0 |
[eluser]aataqwa[/eluser]
I'm using CI 1.7.2 then the alert on the following script is running normally or perform. and if I use CI 2.0 on the same script then alert ('test') does not appear. Code: [removed] how to solve this problem ?
[eluser]Eric Barnes[/eluser]
You are using POST so check and see if you have CSRF protection turned on. And if you do then you need to add it to the post params: Code: data : "action=do&ci;_csrf_token="+$.cookie("ci_csrf_token"), That is using the jquery cookie library. If that is not the case then use firebug and see what your responses are.
[eluser]aataqwa[/eluser]
thanks for replying my post. if $ config ['csrf_protection'] = FALSE; this problem SOLVED. but if I am use with setting: $ config ['csrf_protection'] = TRUE; $ config ['csrf_token_name'] = 'csrf_test_name'; $ config ['csrf_cookie_name'] = 'csrf_cookie_name'; and if I click echo '<input type="button" value="Resend" id="action"> id="action">' and I do not use form_open then the problem is not resolved. please how to solved this problem?
[eluser]Eric Barnes[/eluser]
CSRF expects you to pass the cookie data on any post. So like I said you will have to manually add the cookie to the ajax call.
[eluser]aataqwa[/eluser]
whether the value of csrf_token_name in the hidden text will keep its value forever ? Code: <div class="hidden"> please enlightenment about the value csrf_token_name ??
[eluser]aataqwa[/eluser]
this problem solved with using cookies. thank you very muach mr. Eric Barnes.
[eluser]damien66[/eluser]
Hi, I have the same problem but I don't understand how to resolved that. Can you help me ? My javascript is : Code: $.post("create-account", { name: "John", pass: "test" }, and the Php Code: echo 'data received'; The Php is called and executed but, I can not get the response in my javascript
[eluser]SPeed_FANat1c[/eluser]
hello, I am having the problem too: Code: wrap.load(project_url + 'lt/adminuzsakovai/show-company-activity', I am selecting the csrf_token_name from the form which is generated using form_open(). But when I post this value, I cannot access the function, get an error: "NetworkError: 500 Internal Server Error - http://localhost/autoloadsSVN/lt/adminuz...y-activity" when I go to this page using browsers adrres bar then I can acces that url. If I disable csrd protection, then it also works. Why is it not working even when I post the csrf_token_name ?
[eluser]kaege[/eluser]
I don't understand about csrf_token_name because I use CI 2.0 and, as far as I know, CI 2.0 made no such cookie. The cookie was csrf_test_name. Here's an example from my work: jQuery Code: echo "$.post('".site_url()."/siplhp/welcome', 'name=michael&csrf;_test_name=".$this->input->cookie('csrf_test_name')."', function(data) {alert(data)});"; CI Code: if ($this->input->is_ajax_request()) Remember, CodeIgniter (CSRF in this case) always expect $this->input->post('csrf_test_name') in every POST data. |
Welcome Guest, Not a member yet? Register Sign In |