Hello again. As (somewhat) expected, I couldn't get this to work. Maybe I misunderstood something, but I did the following:
- $.ajax({
- url: 'php/login.php',
- type: 'POST',
- dataType: 'json',
- data: 'user=' + $('#user').val() + '&pass=' + $('#pass').val(),
-
- success: function(result) {
- $('#load').fadeOut(250, function() { // Fading out loading gif
- $(this).remove(); // Removing it
-
- if (result.success) {
- console.log("we succeeded, man");
- }
-
- else {
- console.log("login failed");
- }
- });
- }
- });
And the following is my login.php:
- if (login was successful) {
- $data = array("username" => $_SESSION['username'], "success" => true);
- echo json_encode($data);
- }
- else {
- $data = array("username" => null, "success" => false);
- echo json_encode($data);
- }
I was using a friend's PHP server but it is using an old version of PHP, so the json_encode() method is not yet supported. I then switched to a server running PHP 5.2.13, but that gave me another problem; it just appears to just time out when posting to the PHP script. I am not getting a response in Firebug and after ~21 seconds, it just starts to count errors like crazy for an eternity:
I guess I should check whether the result is null or not, but that still doesn't explain why it seems to time out. Is there anything on the web server's part that could do this, such as a missing feature, low version of something or similar?
Thanks.