-2

Although the ajax call is sending the correct values and they are being written to the database I'm not getting a response back.

I have cut the code down to the minimum to try and locate the error but I still can't get a response...

$(document).ready(function () {
    $('#change_username').click(function(){
        $.ajax({
           dataType: "json",
           type: "POST",
           url: "ajax/change_password_ajax.php",
           data: $('#change_password_form').serialize(),
           success:function(response){
               smeg = (response.message),
               alert(smeg)
               }    

         });
     });
});

change_password_ajax.php

$new_password = $_POST['new_password1'];

$new_password = md5($new_password);
    $sql = "UPDATE user SET password = '$new_password' WHERE userID = '$id'";
    $result = mysqli_query($mysqli,$sql) or die(mysqli_error($mysqli));
    if($result){
        $message = 'yes';   
    }

    $output_array = array(
          'message' => $message,
          'bob' => 'yellow'
        );

echo json_encode($output_array);

If I use Firebug the post to change_password_ajax.php is highlighted in red and there are no response or html tabs but it doesn't give an indication why.

tatty27
  • 1,553
  • 4
  • 34
  • 73

1 Answers1

-1

Edited: Didn't see the first sentence in his question.

In your AJAX call, you have included a "success" callback, but you have not included an "error" callback. If you add one, you will have access to the error object, which is needed for error handling, but can also give you more information on the failure.

However, in your case, you're saying the data is being saved to the database - so the request must be working. The error either lies after the database request is made (the json_encode?) or, the front end in processing the response)

Check your apache log for PHP errors to see if you can pinpoint what's happening.

Edited 2:

Looking at your comments, this other stack overflow question looks like it might glean some answers:

uncaught exception: out of memory in Ajax Process

If your button is a submit button, you might want to preventDefault() on the button.

Community
  • 1
  • 1
Andrew Spode
  • 637
  • 1
  • 7
  • 12
  • I added the error code and get 'uncaught exception: out of memory Line 0'. I've checked the form is serialising ok but it isn't red in the network tab – tatty27 Apr 09 '15 at 15:51
  • back end in the console – tatty27 Apr 09 '15 at 16:11
  • Sorry, can you clarify. Do you mean the javascript console? Is this error in the response from your script, or is that the error javascript is giving? Or is this error in your apache log? – Andrew Spode Apr 09 '15 at 16:14
  • it is the error the javascript script is giving in the console, there are no apache errors for the php – tatty27 Apr 09 '15 at 16:15
  • http://stackoverflow.com/questions/29291952/uncaught-exception-out-of-memory-in-ajax-process I wonder if this answer helps? – Andrew Spode Apr 10 '15 at 12:20
  • My error was that I was converting a php posting form to ajax and the button was still a submit button. Changing it solved the issue, thank you for your help. – tatty27 Apr 11 '15 at 22:48