Can't post with JQuery |
[eluser]pickupman[/eluser]
@Razican: Do you have something in your application/config/routes.php that would tell create a uri path to that method without using the controller name? Also just out of curiosity, what do you have in your .htaccess file?
[eluser]InsiteFX[/eluser]
What version of jQuery are you using? Because some others on the forums here had a problem posting with jQuery 1.5+ jQuery problem posting InsiteFX
[eluser]Razican[/eluser]
I'm using JQuery v1.5.2. I have attached routes.php and .htaccess. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[eluser]InsiteFX[/eluser]
From the forum topic the fix was to use PATH_INFO application/config/config.php Code: $config['uri_protocol'] = "PATH_INFO"; InsiteFX
[eluser]Razican[/eluser]
[quote author="pickupman" date="1303840023"]In Firebug, click on the Console tab. This is probably where you are seeing your log messages already. When the blur or keyup is fired, you should see in your console some like +POST '/yoururl/controller/method/' 200 OK If you click on the + beside POST you should be able to see what variables where posted, and what was returned by the server under the Response tab. Your code looks correct. Try placing an alert before your $.post to see if the event is being fired. Silly to ask, but are you linking to the proper jQuery source?[/quote] I have tried to do debuging in Firebug and I get this: Code: http://127.0.0.1/path/to/registration/request 500 Internal Server Error 41ms POST: Code: username=+ Reply: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> I have the CRSF cookie in my browser. But when I put in the config file $config['csrf_protection'] = FALSE; It works! why?
[eluser]Akinzekeel[/eluser]
When you enable CSRF protection then CI will check $_POST["ci_csrf_token"]. If that's not set then CI will throw an HTTP error - this mechanic also applies to any Ajax based POST requests. To make it work with CSRF you will have to grab the csrf token and post it along with your ajax request. Example: Code: var token = $('input[name=ci_csrf_token]').val(); Remember that by default jQuery will not show any error message when an ajax request returns an HTTP error code.
[eluser]Razican[/eluser]
Thanks, but that wouldn't cause this? Quote:There’s nothing wrong with your $.post Ajax, except that even though you’re defining the variable ‘name’, when you put that into the $.post data, it gets taken literally as the word ‘name’, not the variable value as defined earlier. I’d suggest not defining name and value, and replacing the data object with $(this).serialize() I have tried to do it. Firebug says this: POST: Code: name xfc The problem is it sends name instead of username.
[eluser]Akinzekeel[/eluser]
I'm no expert at JavaScript but I think you cannot use a variable as key. I am referring to this code which you have posted here: Code: $(function(){ Try this instead (might require some POST variable adjustments in your PHP script): Code: $(function(){ By the way, I did not read this thread entirely so excuse if I didn't nail your problem right away. But I am still quite sure that you also need to send the CSRF token if you enable CSRF in your configuration.
[eluser]Razican[/eluser]
And could I use $(this).serialize()? But then How could add to that array the csrf token? |
Welcome Guest, Not a member yet? Register Sign In |