Welcome Guest, Not a member yet? Register   Sign In
Can't post with JQuery
#11

[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?
#12

[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
#13

[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');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
|    example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
|    http://ellislab.com/codeigniter/user-guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There area two reserved routes:
|
|    $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
|    $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router what URI segments to use if those provided
| in the URL cannot be matched to a valid route.
|
*/

$route['default_controller'] = "welcome";
$route['404_override'] = '';

// URI like '/en/about' -> use controller 'about'
$route['^en/(.+)$'] = "$1";
$route['^es/(.+)$'] = "$1";
$route['^eu/(.+)$'] = "$1";

// '/en' and '/es' URIs -> use default controller
$route['^en$'] = $route['default_controller'];
$route['^es$'] = $route['default_controller'];
$route['^eu$'] = $route['default_controller'];


/* End of file routes.php */
/* Location: ./application/config/routes.php */
#14

[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
#15

[eluser]Razican[/eluser]
Using PATH_INFO I can't load the page.
#16

[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">
&lt;html &gt;
&lt;head&gt;
&lt;title&gt;Error&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" /&gt;
&lt;style type="text/css"&gt;

::selection{ background-color: #E13300; color: white; }
::moz-selection{ background-color: #E13300; color: white; }
::webkit-selection{ background-color: #E13300; color: white; }

body {
    background-color: #fff;
    font: 13px/20px normal Helvetica, Arial, sans-serif;
    color: #4F5155;
}

a {
    color: #003399;
    background-color: transparent;
    font-weight: normal;
}

h1 {
    color: #444;
    background-color: transparent;
    border-bottom: 1px solid #D0D0D0;
    font-size: 19px;
    font-weight: normal;
    margin: 0 0 14px 0;
    padding: 14px 15px 10px 15px;
}

code {
    font-family: Consolas, Monaco, Courier New, Courier, monospace;
    font-size: 12px;
    background-color: #f9f9f9;
    border: 1px solid #D0D0D0;
    color: #002166;
    display: block;
    margin: 14px 0 14px 0;
    padding: 12px 10px 12px 10px;
}

#container {
    clear: both;
    margin: 10px;
    border: 1px solid #D0D0D0;
    -webkit-box-shadow: 0 0 8px #D0D0D0;
}

p {
    margin: 12px 15px 12px 15px;
}
&lt;/style&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;

I have the CRSF cookie in my browser. But when I put in the config file $config['csrf_protection'] = FALSE; It works! why?
#17

[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();
$.post("can't put links", { name: value, ci_csrf_token: token }, function(data) {
    alert(data);
});

Remember that by default jQuery will not show any error message when an ajax request returns an HTTP error code.
#18

[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
and the CSRF

The problem is it sends name instead of username.
#19

[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(){
    $('input').bind('blur keyup', function()
    {
        $('#form_result').html(loading);
        var name    = $(this).attr('name'),
            value    = $(this).val();
        $.post("can't put links", { name: value }, function(data) {
            alert(data);
        });
    });
});

Try this instead (might require some POST variable adjustments in your PHP script):
Code:
$(function(){
    $('input').bind('blur keyup', function()
    {
        $('#form_result').html(loading);
        var n    = $(this).attr('name'),
            v    = $(this).val();
        $.post("can't put links", { name: n, value: v }, function(data) {
            alert(data);
        });
    });
});

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.
#20

[eluser]Razican[/eluser]
And could I use $(this).serialize()? But then How could add to that array the csrf token?




Theme © iAndrew 2016 - Forum software by © MyBB