In this tutorial, I will show you how to integrate sweetalert 2 in PHP & MySQL using Ajax. Sweet alert 2 allows us to customize the alert box in our web applications and the look and feel are amazing that many developers loving it. So in this article, I will share how to integrate it easily into our applications. Show
Creating Index HTMLSo, let start first by creating our index.html file. See the code below.
As you can see above we imported sweetalert2 javascript and styles.
Implement Sweetalert with Saving Record using Ajax?So in our previous tutorials, we are just using the native javascript alert after successfully created the record. As you can see below screenshot.
So we will replace it now using the awesome design of sweetalert2. Please check the below code on who to do it.
In our save function above you will see a code that started with Swal.fire inside the ajax success. As you can see below.
Now since we already added our sweetalert2 so if we saving a new record the alert box will appear like this shown below.
Since we already implement the basic one. Next, we will implement the Confirm dialog type sweetalert 2.
Implement Dialog Type Sweetalert with Ajax Delete on PHP & MySQLBelow is an example code about the dialog type sweetalert 2 that we are going to use for confirming the record deletion.
Since you have the sample code about we will next tackle the full code on how to implement it with ajax delete. Kindly check the below code.
Okay, you are ready now implementing sweet alert 2 with your project. So it's time to take a look at the actual actions of this code. Just click the download button below to get the complete source code of this tutorial. |