Welcome Guest, Not a member yet? Register   Sign In
jQuery $.post and CI
#1

[eluser]damien66[/eluser]
Hi,

I have a problem on my web application with jQuery $.post.

My javascript is :

Code:
$.post("create-account", { name: "John", pass: "test" },
   function(data) {
     alert("Data Loaded: " + data);
   });

and the Php
Code:
echo 'data received';

The Php is called and executed but, I can not get the response in my javascript

Can you help me ?

thanks :)
#2

[eluser]InsiteFX[/eluser]
Search the forums this has been answered a 100 times!

CSRF cookie in the config.php file.

You have to pass the cookie value to jQuery

InsiteFX
#3

[eluser]damien66[/eluser]
I can not find $config['CSRF'] on my config.php file...
#4

[eluser]steelaz[/eluser]
What are your response headers for AJAX request in Firebug?
#5

[eluser]damien66[/eluser]
Quote:Réponsevoir le code source
Set-Cookie 60gp=R152070632; path=/; expires=Fri, 04-Mar-2011 00:16:00 GMT
Date Tue, 01 Mar 2011 11:59:41 GMT
Server Apache/2.2.X (***)
X-Powered-By PHP/5.3.5
Vary Accept-Encoding
Content-Encoding gzip
Content-Length 60
Keep-Alive timeout=5, max=100
Connection Keep-Alive
Content-Type text/html
RequĂȘtevoir le code source
Host mysite*********
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Accept */*
Accept-Language fr,fr-fr;q=0.8,en-us;q=0.5,en;q=0.3
Accept-Encoding gzip,deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive 115
Connection keep-alive
Content-Type application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With XMLHttpRequest
Referer http://mysite*********
Content-Length 122
Cookie 60gp=R152070632; ci_session=a:4:{s:10:"session_id";s:32:"d7d2cc52db790a529e47b77656bf7acd";s:10:"ip_address";s:13:"******";s:10:"user_agent";s:50:"Mozilla/5.0+(Windows;+U;+Windows+NT+6.1;+fr;+rv:1.";s:13:"last_activity";s:10:"1298980677";}17fbb6b53141cc1cf003af586b186b33

Is it what you need ?
On firebug I see the response but javascript can not retrieve it
#6

[eluser]steelaz[/eluser]
Look like you're getting your response back (Content-Length: 122). Try

Code:
$.post("create-account", { name: "John", pass: "test" },
   function(data) {
     console.log(data);
     alert("Data Loaded: " + data);
   });

and check Firebug console for returned variable.
#7

[eluser]damien66[/eluser]
Ok, I have add the console.log and no effect.

I put a break point on the console.log and no effect...

The function contents isn't executed :O

Do you have an idea ?
#8

[eluser]steelaz[/eluser]
Does Firebug report any errors? Try replacing post() with more customizable ajax():

Code:
$.ajax({
    type: "POST",
    url: "create-account",
    data: "name=John&pass=test",
    success: function(){
        console.log('success')
    },
    error: function(){
        console.log('error')
    },
    complete: function(){
        console.log('completed')
    }
});
#9

[eluser]damien66[/eluser]
error
completed

and the firebug msg is now :

"404 Page Not Found</h1>
<p>The page you requested was not found."
#10

[eluser]steelaz[/eluser]
Check your request headers and make sure URL is correct, change
Code:
url: "create-account"
accordingly.




Theme © iAndrew 2016 - Forum software by © MyBB