tags:

views:

96

answers:

1

for some reason the success function isnt being called?

javscript:

$.ajax({  
            type: 'POST',
            url: 'http://localhost/hf_latest_desktop/st_pages/user_area/acc_buttons/pass_change/pass_change_ajax.php',
            data: data,
            dataType: 'json',
            success: function(e){ 
                console.log(e);
                if(e.status == 'success'){
                    alert('your password has been changed!');
                }   
                if(e.status == 'error1'){
                    alert('please fill in all inputs!');
                }
                if(e.status == 'error2'){
                    alert('password incorrect!');
                }
                if(e.status == 'error3'){
                    alert('change failed!');
                } 
            } 
        }); 

php file ajax is calling to:

    <?php session_start();
    session_cache_limiter('nocache');
    header('Expires: ' . gmdate('r', 0));
    header('Content-type: application/json');
    $status = 'error1'; //for sake of example
    ?>
    {'status':'<?php echo $status; ?>'} 
+1  A: 

Add the error handler to see what is being returned.

$.ajax({
   type: 'POST',
   dataType: 'text/json',
   url: 'myUrl',
   success: function(data, status) { },
   error: function(data, status)
   {
      alert(data); // Print the response!
   }
});
Tejs
logging to the console i get: from the error: XMLHttpRequest { onreadystatechange=[xpconnect wrapped nsIDOMEventListener], more...}
Haroldo
so im getting an error response i just dont know what it means!
Haroldo
Try just alerting the data you receive back. It should be the HTML you are receiving from the server.
Tejs
the response is: {'status':'error2'}
Haroldo
Keep-Alive timeout=5, max=100Connection Keep-AliveContent-Type application/json
Haroldo
Try changing the data type to 'text/html' and see if that makes a difference.
Tejs