0

Well, another try:

this is all the jquery code i'm using maybe i made something wrong in the code before $.post(); i call the following function with the onclick of the same form...

function setLogin()
{

$('#login-form').submit(function(e) {
    e.preventDefault();
            //passing form field to vars
    var formUsername=$("#login-form #username").val();
    var formPassword=$("#login-form #password").val();
            //checks on fields lenght
    if((formUsername.length<6))
    {
        $("#ajax-output").html("<div class='error'>Attenzione username troppo breve!</div>");
    }
    else if((formPassword.length<6))
    {
        $("#ajax-output").html("<div class='error'>Attenzione password troppo breve!</div>");
    }
    else
    {
        $.post(
                            //the url
            '?module=login',

                            //data got from login form
            {
                "username": formUsername,
                "password": formPassword,
            },
            //response
            function(data){
                $("#ajax-output").html(data.reply)
            },
            //type
            "json"

        );
    }
});
}

i tried with only this code in php file and it still doesn't return anything...

function Login()
{
    //just to try
echo json_encode(array('reply'=>'foo'));
}

it still doesn't work...

Antonio Ciccia
  • 726
  • 3
  • 8
  • 18

2 Answers2

2

Are you sure the post is being run in the first place?

Use Firebug! (or chrome's built-in developer tools)

You can use firebug to pick apart every bit of a web page.

It has a "net" tab that shows every request that is made by the browser, including AJAX requests, and their results, headers and contents.

Use it to see if your requests is really being made, and what the result is. Then take it from there.

Michael Slade
  • 13,802
  • 2
  • 39
  • 44
0

Make sure that you're setting a header for the content type when responding - the browser may not attempt to use the JSON if it doesn't know it's receiving JSON.

function Login()
{
    header('Content-Type: application/json');
    echo json_encode(array('reply'=>'foo'));
}
Clay Hinson
  • 932
  • 1
  • 6
  • 9