Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to display the messages on my popup form without a page reload but when I hit the button it reloads the page and no message shows.

My Controller:

$current_password = $user->password;
if(md5($request_data['password']) == $current_password) {
    $user_id = $user->id;
    $obj_user = User::find($user_id);
    $obj_user->password = md5($request_data['new_password']);;
    $obj_user->save();
    return response()->json([
        'success_message' => 'password has been changed successfully',
    ], 422);
} else {
    return response()->json([
        'modal_message_danger' => 'wrong old password'
    ], 422);
}

My Ajax:

$('#password_change_form').submit(function(e) {
   e.preventDefault();
   var saveThis = this;
   $.ajax({
     type: "POST",
     url: "/changepassword",
     data: $(saveThis).serialize(),
     success: function(data) {
        alert(data);
     }
   });
});

But it does nothing; Ajax is not working. I want to display the message.

currently it's showing like this

this is my popup form where I want to display my message

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
300 views
Welcome To Ask or Share your Answers For Others

1 Answer

To get jquery object, I think you need to change

var saveThis = this;

to

var saveThis = $(this);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...