CodeIgniter Forums
using jquery ajax with codeigniter - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: using jquery ajax with codeigniter (/showthread.php?tid=55895)

Pages: 1 2 3


using jquery ajax with codeigniter - El Forum - 11-15-2012

[eluser]johnpeace[/eluser]
Do it again and show the response this time...or put it on a webserver and send me a URL


using jquery ajax with codeigniter - El Forum - 11-15-2012

[eluser]fatfishy[/eluser]
[quote author="johnpeace" date="1352995167"]Do it again and show the response this time...or put it on a webserver and send me a URL[/quote]

I dont have webserver, anyway this is the response
Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;title&gt;Error&lt;/title&gt;
&lt;style type="text/css"&gt;
...
&lt;/head&gt;
&lt;body&gt;
<div id="container">
  <h1>An Error Was Encountered</h1>
  <p>The action you have requested is not allowed.</p> </div>
&lt;/body&gt;
&lt;/html&gt;



using jquery ajax with codeigniter - El Forum - 11-15-2012

[eluser]benton.snyder[/eluser]
Try to set the following in your application/config/config.php:

Code:
$config['global_xss_filtering'] = FALSE;

Do you receive the same Error Encountered response?


using jquery ajax with codeigniter - El Forum - 11-15-2012

[eluser]fatfishy[/eluser]
[quote author="benton.snyder" date="1352997568"]Try to set the following in your application/config/config.php:

Code:
$config['global_xss_filtering'] = FALSE;

Do you receive the same Error Encountered response?[/quote]
Still 500 error as before :/

Thanks!


using jquery ajax with codeigniter - El Forum - 11-15-2012

[eluser]benton.snyder[/eluser]
Code:
var usernameRequest = $.ajax({
  type: "POST",
  url: "http://127.0.0.1/index.php/ajax/username_taken",
  data: { username:username },
  dataType: 'html'
});

// successful ajax response
usernameRequest.done(function(result) {
alert("Success!");
});

// failed ajax response
usernameRequest.fail(function(jqXHR, textStatus) {
alert("ajax request failed: " + textStatus);
});



using jquery ajax with codeigniter - El Forum - 11-15-2012

[eluser]CroNiX[/eluser]
The only place that error (The action you have requested is not allowed.) comes from is when CSRF protection fails.

So my guess is you have CSRF enabled but are not sending the CSRF name/value in your ajax POST request which would validate that request - so it's being rejected (as it should). Search the forums for how to solve this common problem ("csrf+ajax")

If you use CSRF, everything POSTed needs to have the token name and value passed or it will get rejected. That's it's purpose.



using jquery ajax with codeigniter - El Forum - 11-15-2012

[eluser]fatfishy[/eluser]
[quote author="CroNiX" date="1353011212"]The only place that error (The action you have requested is not allowed.) comes from is when CSRF protection fails.

So my guess is you have CSRF enabled but are not sending the CSRF name/value in your ajax POST request which would validate that request - so it's being rejected (as it should). Search the forums for how to solve this common problem ("csrf+ajax")

If you use CSRF, everything POSTed needs to have the token name and value passed or it will get rejected. That's it's purpose.
[/quote]

that seems to be the problem, I've googled it and I found the solution.
thanks everyone for the help Smile