In this tutorial, we are going to give you a fix to an error that prevents you from creating an iCloud account. Ever run into this error while creating an @icloud email?
“your account cannot be created at this time”
I recently faced this error and this is how I have solved it:
If you prefer a video tutorial, you can check our YouTube tutorial.
In this article, we are going to show you, how you can change title text of an HTML page using simple Javascript. We will show a real-time notification to your users in their title bar using PHP, MySQL, and Node JS. You can show a notification in a title bar with just PHP and MySQL. But the “real-time” effect can only be achieved with Node JS.
We can change title text using Javascript’s document.title object, but we will show you with a real-world example.
What we will do:
Save notification in the database
Display counter in the title bar
Show all unread notifications to the user
Mark notification as read
Make notifications real-time
1. Save notifications in the MySQL database
First, we need to save the notifications in the database. Notifications can be of any type, for example, “a new message is received” or “your account has been activated” etc. We will create a new file named “send-notification.php“.
Comments have been added with each line for an explanation. Run the above code and check your database, you will see a new table named “notifications” and also a new row is inserted in that table. Now we need to display this on the user side.
2. Display the counter in the title bar
We just need to fetch the total number of unread notifications from the database and display them in the user’s title bar. Create a new file named “index.php” and it will have the following code:
Then we need to fetch this variable in Javascript and prepend it in the title bar. First, we need to create a title tag and a hidden input field where we will put the above variable value.
1
2
3
4
5
<!-- title where notification number will be displayed -->
<title>My Website</title>
<!-- save variables in hidden input field to access in Javascript -->
Then we need to get this input field value in Javascript and render it in the title tag. We will create a separate Javascript function to render the title bar because we will need it in multiple situations when:
This will first check if the value of variable totalUnreadNotifications is greater than 0. If it is 0, then we will not show any number at all (not even 0). Then we will check if there is already any value in the title bar. If there is any value, then we will simply increment the counter value and re-render the title bar.
If there isn’t any value already in the title bar, then we will simply prepend the counter before the title tag content.
Here, the document.title is the only line that change title text.
This does change title text because initially, it was only “My Website”. After a notification is fetched from database, it prepends the value in the <title> tag.
At this point, you are seeing the number of unread notifications in your title bar. Now you need to find a way to mark notifications as “read” and decrement the counter.
3. Show all unread notifications to the user
To mark notifications as “read”, we first must show all the notifications to the user which when clicked will be marked as “read”. After that, the counter will be decremented and the title tag will be re-rendered. We will create a new file named “notifications.php” to display all notifications to the user.
// get all notifications sorting by unread goes first
$sql= "SELECT * FROM notifications WHERE user_id = ? ORDER BY is_read ASC";
$statement= $conn->prepare($sql);
$statement->execute([
$_SESSION["user_id"]
]);
$notifications= $statement->fetchAll();
This will fetch all the notifications of the logged-in user. Now we need to display them in an HTML table. We will simply by displaying a notification message and a button to mark that notification as read.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<!-- show all notifications in a table -->
<table>
<tr>
<th>Message</th>
<th>Action</th>
</tr>
<?php foreach($notificationsas$notification): ?>
<tr>
<td><?php echo$notification['message']; ?></td>
<td>
<!-- show 'read'button only ifthe notification is un-read -->
If you refresh the page now, you will see a list of all notifications with the button “read”. On clicking that button, we need to call an AJAX request to the server to mark this notification as “read” in the MySQL database. We will be using Vanilla JS to do that, no jQuery or any other external library is being used.
Now we need to create this Javascript function that will actually send the AJAX request. We will be using AJAX because there will be a lot of notifications and it will not be a good idea to keep refreshing the page for each notification to be marked as read.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<script>
// when the read button is clicked
functionmarkAsRead() {
// prevent the form from submitting
event.preventDefault();
// get the form node
varform = event.target;
// create AJAX object
varajax = newXMLHttpRequest();
// set method and URL of request
ajax.open("POST", "read-notification.php", true);
// when the status of request changes
ajax.onreadystatechange = function() {
// when the response is received from server
if(this.readyState == 4) {
// if the response is successful
if(this.status == 200) {
// convert the JSON string into Javascript object
vardata = JSON.parse(this.responseText);
console.log(data);
// if there is no error
if(data.status == "success") {
// remove the 'read' button
form.remove();
// [emit read notification event here]
}
}
}
};
// create form data object with the form
varformData = newFormData(form);
// send the AJAX request with the form data
ajax.send(formData);
}
</script>
This will prevent the form from redirecting and calling our Javascript code. After the notification is successfully marked as read from the server, we will remove the “read” button. The last thing we need is a server-side PHP file that will handle this request.
4. Mark notification as read
Now we need to create a new file named “read-notification.php” that will mark this notification as “read”. In this file, we will also check the user_id along with the notification ID to make sure that the notification we are marking is “read” is actually sent to the logged-in user.
$sql= "UPDATE notifications SET is_read = 1 WHERE id = ? AND user_id = ?";
$statement= $conn->prepare($sql);
$statement->execute([
$id,
$_SESSION["user_id"]
]);
// send the response back to client
echojson_encode([
"status"=> "success"
]);
exit();
This file will first check that the notification ID sent from AJAX actually refers to the logged-in user. Because someone can try to tamper with the client-side code and mark any other user’s notification as “read”. So we must do server-side validation like above.
At this point, if you run the code now, you will be able to see all the notifications in an HTML table with a “Read” button. When clicked, will mark the notification as read and also will remove the “read” button.
If you refresh the “index.php” file, you will now see the counter in the title bar will be decremented. One more thing you can do is to make it real-time, so when there is any notification added, the counter will be incremented in the title bar. And also when the notification is read by the user, then the counter should be decremented automatically.
5. Make notifications real-time
Making these notifications in real-time is crucial. You might have used the WhatsApp Web where you will see that the counter in the title bar automatically gets incremented and decremented based on the number of new notifications you received and the notifications have you read.
Now we need to learn how you can implement this functionality in your project. We will be using the Socket IO JS library for this and we will also create a small Node JS server for this purpose. You can download Socket IO JS from their official site.
After downloading, you need to paste the JS file into your project. You also need to download and install Node JS in your system, you can download it from here.
Setting up Node JS server
After Node JS installation, open the command prompt or terminal in your project root directory and run the following command:
1
npm init
This will ask a couple of questions, you can press “enter” for all questions and it will automatically set the default answer. Then we need to install the required modules for this feature. Run the following command in your terminal:
1
npm installexpress http socket.io
This will install the Express, HTTP, and Socket IO module in your Node JS app. To start the server, we need to install another module globally named “nodemon“. So again, run the following command in your terminal:
1
npm install -g nodemon
Typically when you made changes in your code, you need to manually restart the Node JS server. But it slows down the process during development. So this module automatically restarts the server if there is any change in the server file.
Create a new file named “server.js“, this will be our Node JS server file. Paste the following code in that file, we will explain this in the next step:
// called manually from client to connect the user with server
socket.on("connected", function(id) {
users[id] = socket.id;
});
});
});
In this file we are:
Initializing the Express framework and also HTTP module.
Including the Socket IO module. You can place your own server URL in the CORS origin array.
Then we are starting the server at port 3000. We use process.env.PORT on deployment.
When a new user is connected with a server, a unique socket ID is generated. We are saving each user’s socket ID in a local array along with his ID from the database.
Now is the time to start the server. Run the following command in your terminal to start the server.
1
nodemon server.js
If you check the terminal, you will see a message “Server started running…” this means that you are ready to send connect your client-side with this server.
Increment counter on new notification
Whenever a new notification is sent to the server, we need to automatically increment the counter in the title bar. We have already created a function in “index.php” that displays the counter in the title bar.
To add this feature we need to perform the following tasks:
Connect socket IO JS on the “send-notification.php” file.
Then emit (send) the notification event to the Node JS server along with the ID of the user.
On the Node JS server-side, listen to that event and emit the event to the relative user.
Connect socket IO JS on the “index.php” file.
Listener for that new notification event.
When that event is received, increment the counter and re-render the title.
The following code goes in the “send-notification.php” file after the notification is inserted in the database:
We are already creating the $user_id variable in the first step. Then we are simply including the socket IO JS library and connect with the Node JS server. Getting the user ID from the hidden input field. And finally emitting an event to the server with a user ID.
In your “server.js” listen to this event and emit the event to the user with the same ID.
The event has been dispatched from the server to the client. Now the client must listen to this event and when received should increment the counter and re-render the title. The following code goes in your “index.php“:
Open “index.php” and “send-notification.php” in separate tabs and refresh both of these pages. Every time you refresh the send notification page, you will see the title of the index file gets incremented. Now we need to do the same for reading notifications, except that the title bar will be decremented whenever a notification is marked as read.
Decrement counter on reading notification
In “notifications.php” first, we need to include the socket IO JS library and connect with the server.
Similarly, you need to create a listener on the user side too in the index.php file.
1
2
3
4
socketIO.on("notificationRead", function(data) {
totalUnreadNotifications--;
showTitleBarNotifications();
});
This also change title text, but this time it decrements the counter value.
Run the code now and refresh both of your browsers. And try to read some notifications, as soon as you read them, you will see that the counter in the title bar will be decremented too.
So that’s how you can change title text of an HTML page using vanilla Javascript.
Conclusion
So that’s how you can implement a real-time notification system in your website with an unread notification counter in the title bar using simple PHP, Javascript, and Node JS. There is no PHP or Javascript framework used in this tutorial, so you can work with it with any framework in your existing project.
That’s how you can change the title text of the browser tab. If you face any problems in following this, kindly do let me know in the comments section below.
In this article, we are going to show you how you can implement a Google sign in on your website using Javascript and PHP. We will use Javascript to render the button. And we will use PHP to verify the token generated by the Google client because anyone can try to tamper with the client-side code.
Then we need to render the <div> tag with the sign in button. Make sure to replace the {your_google_client_id} code with your Google client ID generated from 1st step.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<script>
// variable to check that the button must be clicked manually
// send an AJAX request to the server to verify the token
varajax = newXMLHttpRequest();
ajax.open("POST", "google-sign-in.php", true);
// when the status of request is changed
ajax.onreadystatechange = function() {
// when the response is received from server
if(this.readyState == 4) {
// if the server is successfull
if(this.status == 200) {
// the response will be a JSON string, convert that into javascript object
vardata = JSON.parse(this.responseText);
console.log(data);
}
// if there is any internal server error
if(this.status == 500) {
console.log(this.responseText);
}
}
};
// create form data object
varformData = newFormData();
// append the token in the request
formData.append("id_token", id_token);
// send the request
ajax.send(formData);
},
onfailure: (error) => {
console.log(error);
}
});
});
});
}
</script>
Refresh the page now and you will be able to see a Google sign-in button. By default, you will see the message “Sign-in with Google”. Once you click the button and sign in with your Google account, you will see your profile information in the browser console.
4. Verify token
The token generated from the sign-in button must be verified from the server-side because anyone can tamper with the client-side code. To verify this token we are already sending an AJAX request. Now we need to create a new file named “google-sign-in.php” and paste the following code into it.
Make sure to replace the value of $google_oauth_client_id variable with your own client ID.
Refresh the page now and try to log in again. Now we will also see a success response in your browser console, that is because of an AJAX request. On the server side, you can register the user if he is not already registered or you can start his session if he is already registered.
So that’s how you can implement a Google sign-in button in your website using plain Javascript and PHP. Try to implement this in your live site and let us know in the comments section if there is any problem.
In this tutorial, we are going to teach you how to create a dynamic FAQ section on your website using PHP and MySQL. We will create simple CRUD (Create, Read, Update, Delete) operation using PHP PDO. FAQs will be added, updated, and deleted from the admin panel. And they will be displayed on the user side.
Usually, the FAQ section is displayed statically. But it would be great if you can manage it from your admin panel. That’s why we should choose dynamic FAQ section over hard-coded one.
Table of content:
Add FAQ from the admin panel
Display all FAQs to the admin
Edit any FAQ
Delete FAQ
Display FAQs on the user side
We will be using PHP PDO prepared statements to prevent SQL injection. We will be using bootstrap, jQuery, font-awesome, and richText libraries in this tutorial. All source files can be downloaded at the end of this article. Download all these libraries and paste them into your project.
1. Add FAQ
First, we will create a file named “add.php“. In this file, we will first include the above libraries.
1
2
3
4
5
6
7
8
<!-- include bootstrap, font awesome and rich text library CSS -->
Then you need to initialize the richText library to make the textarea field with more options like text styles, fonts, lists, tables, and images, etc. Following Javascript code will do that:
1
2
3
4
// initialize rich text library
window.addEventListener("load", function() {
$("#answer").richText();
});
Then we will handle this request in the same file. We will create the required table in the MySQL database dynamically. Then we will insert a new row with questions and answers entered in input fields.
$sql= "INSERT INTO faqs (question, answer) VALUES (?, ?)";
$statement= $conn->prepare($sql);
$statement->execute([
$_POST["question"],
$_POST["answer"]
]);
}
// [query to get all FAQs]
?>
Run the code now and you will be able to see a form with 2 input fields. When hit submit, you will see a new table will be created in your database. And a new row will be inserted in that table. Add a few more questions and their answers using the form.
2. Display all FAQ
Now we need to display all added FAQs to the admin side. In the same add.php file, the following code goes in the [query to get all FAQs] section:
1
2
3
4
5
// get all faqs from latest to oldest
$sql= "SELECT * FROM faqs ORDER BY id DESC";
$statement= $conn->prepare($sql);
$statement->execute();
$faqs= $statement->fetchAll();
This will fetch all the questions sorted by newest to oldest. Now we need to display all of them on a table. The following code goes in the [show all FAQs here] section:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<!-- show all FAQs added -->
<divclass="row">
<divclass="offset-md-2 col-md-8">
<tableclass="table table-bordered">
<!-- table heading -->
<thead>
<tr>
<th>ID</th>
<th>Question</th>
<th>Answer</th>
<th>Actions</th>
</tr>
</thead>
<!-- table body -->
<tbody>
<?phpforeach ($faqs as $faq): ?>
<tr>
<td><?phpecho $faq["id"]; ?></td>
<td><?phpecho $faq["question"]; ?></td>
<td><?phpecho $faq["answer"]; ?></td>
<td>
[edit button goes here]
[delete button goes here]
</td>
</tr>
<?phpendforeach; ?>
</tbody>
</table>
</div>
</div>
Refresh the page now and you will be able to view all the inserted questions sorting by newest to oldest.
3. Edit any FAQ
Following are the steps to update any specific row in the MySQL database using PHP PDO prepared statement:
Show a link to go to edit page with each row
Fetch the row data from MySQL using ID from URL
Create a same form like add.php
Auto-populate the values in the input fields
Create a hidden input field for ID
Update the data in database using ID
Redirect to previous page
1. Show a link to go to edit page
Following code goes in the [edit button goes here] section:
Refresh the page now and you will see an edit link with each row. Then create a file named “edit.php” that will handle this request.
2. Fetch the row from MySQL
You will see an ID in the URL in the browser’s address bar. We need to get this value and search it in the MySQL database. This file will be similar to add.php but with auto-populate values in the input fields. First, we will fetch the row from the database.
If you refresh the page now, you will see the same form as the added FAQ but the input fields are auto-populated with selected FAQ values. It will also have a hidden input field for the ID.
6 & 7. Update the data and redirect back
Now we need to handle the update request. In the edit.php file, replace the [update query goes here] section with the following code to update the data in the database.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// check if edit form is submitted
if(isset($_POST["submit"]))
{
// update the FAQ in database
$sql= "UPDATE faqs SET question = ?, answer = ? WHERE id = ?";
$statement= $conn->prepare($sql);
$statement->execute([
$_POST["question"],
$_POST["answer"],
$_POST["id"]
]);
// redirect back to previous page
header("Location: ". $_SERVER["HTTP_REFERER"]);
}
Refresh the page now and try to update any FAQ. You will see that it will be updated in the MySQL database as well as in the HTML table too.
4. Delete FAQ
First, we need to show a delete button with each row. It will be a form with a hidden input field that contains the value of that FAQ. When that form is submitted, we will again first check if the record exists in the database. If yes, then we will simply remove it.
The following code goes in the [delete button goes here] section of the add.php file:
1
2
3
4
5
<!-- deleteform -->
<form method="POST"action="delete.php"onsubmit="return confirm('Are you sure you want to delete this FAQ ?');">
If you refresh the page now, you will see a red delete button with each row. On clicking, it will ask for confirmation. When confirmed, it will remove the FAQ from the MySQL database using PHP.
5. Display FAQs on the user side
Now comes the final part, where we will display our dynamic FAQ on the user side. Typically we have an index.php as our website home page. But you might have a separate page for FAQs. Either way, you first need to fetch all the data from the database:
Run the code now and you will see a beautiful accordion with a question, which when clicked will display an answer. You can add as many questions and their answer from the database and they will be displayed here automatically.
So that’s how you can create a dynamic FAQ section on your website that can be managed from your admin panel.
Learn how to add dynamic testimonial section on your website from here.
In this tutorial, we are going to teach you how you can add a dynamic testimonial to your website using PHP and MySQL in the backend and Vue JS in the frontend. Testimonials are displayed on a website to show the new users how your product satisfies your previous customers. We will be creating 2 pages, one for adding testimonials from the admin panel. And second to display all testimonials in a beautiful design.
If you do not have a dynamic testimonial, then you have to manually add, modify or delete a testimonial from your website. By going dynamic, you can perform all these actions from your admin panel.
Add Testimonial
First, download Bootstrap from here and Vue JS from here. Paste the CSS and JS files in your project, we will be using them in a moment. After that, we need to create a form from which we can add testimonials. Each testimonial will have a picture of the person, name, designation in his company, and his comments.
The following code goes in your admin panel from where you want to add testimonials.
This will show a form with input fields. But when you click on the “Add Testimonial” button, nothing happens. This is because we need to render it using Vue JS.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<script>
// initialize vue js app
varaddTestimonialApp = newVue({
el: "#addTestimonialApp", // id of container div
data: {
// all values used in this app
testimonials: []
},
// all methods
methods: {
// [other methods goes here]
// called when form is submitted
store: function() {
// get this app instance
varself = this;
varform = event.target;
// call an AJAX to create a new entry in testimonials
varajax = newXMLHttpRequest();
ajax.open("POST", "store.php", true);
ajax.onreadystatechange = function() {
if(this.readyState == 4) { // response received
if(this.status == 200) { // response is successfull
// console.log(this.responseText);
// parse the response from JSON string to JS arrays and objects
varresponse = JSON.parse(this.responseText);
// console.log(response);
alert(response.message);
// if there is no error
if(response.status == "success") {
self.testimonials.unshift(response.testimonial);
form.reset();
} else{
// when there is any error
}
}
if(this.status == 500) {
console.log(this.responseText);
}
}
};
// create form data object and form to it
varformData = newFormData(form);
// actually sending the request
ajax.send(formData);
},
},
// [mount code goes here]
});
</script>
Refresh the page now and you will be able to submit the form, this is because of Vue JS. An AJAX request will be sent to the server to store the picture attached and save the other fields in the MySQL database using PHP.
Create a new file named “store.php” and paste the following code in it:
If you refresh the page now, upload the picture, enter the fields and hit submit, it will create a new table in the database if not already created. Then it will create a folder named “testimonials” and save the image file in it. Then it will insert a new row in it. And finally, it will return the new row back to the client (AJAX).
From there we will prepend it in our local testimonials array. Now we need to display all the added testimonials in an HTML table with a button to delete them.
Display all Testimonials to Admin
The following code goes in the [show all testimonials for deleting] section:
This will create an empty HTML table because we need to load the in it first. We will call an AJAX to fetch all the stored testimonials using PHP and MySQL and display them using Vue JS. The following code goes in the [mount code goes here] section:
1
2
3
mounted: function() {
this.getData();
}
Now we need to create a function named “getData” in our Vue JS instance. Replace the code in section [other methods goes here] with the following:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// [delete method]
getData: function() {
// get this app instance
varself = this;
// call an AJAX to get all testimonials
varajax = newXMLHttpRequest();
ajax.open("POST", "fetch.php", true);
ajax.onreadystatechange = function() {
if(this.readyState == 4) { // response received
if(this.status == 200) { // response is successfull
// console.log(this.responseText);
// parse the response from JSON string to JS arrays and objects
varresponse = JSON.parse(this.responseText);
// console.log(response);
// if there is no error
if(response.status == "success") {
self.testimonials = response.data;
} else{
// when there is any error
}
}
if(this.status == 500) {
console.log(this.responseText);
}
}
};
// create form data object
varformData = newFormData();
// actually sending the request
ajax.send(formData);
},
Finally, we need to create a new file named “fetch.php” that will fetch all the testimonials from the MySQL database using PHP.
Refresh the page now and you will be able to see all the testimonials added. Also, if you add a new testimonial, it will automatically be prepended in the HTML table. Now we need to make it able to delete the testimonial.
Delete Testimonial
We need to follow the following steps to delete the testimonial:
Call an AJAX with an ID of testimonial.
On server side, fetch the testimonial using ID.
Delete the picture from the “testimonials” folder using PHP unlink() function.
Delete the testimonial from MySQL database.
Send the response back to client.
The client will remove the testimonial from local array.
It will automatically be removed from the HTML table.
Replace the section [delete method] with the following code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// method to delete testimonial
deleteTestimonial: function() {
// get this app instance
varself = this;
// get form
varform = event.target;
// call an AJAX to delete the testimonial
varajax = newXMLHttpRequest();
ajax.open("POST", "delete.php", true);
ajax.onreadystatechange = function() {
if(this.readyState == 4) { // response received
if(this.status == 200) { // response is successfull
// console.log(this.responseText);
// parse the response from JSON string to JS arrays and objects
varresponse = JSON.parse(this.responseText);
console.log(response);
// remove from local array if deleted from server
if(response.status == "success") {
for(vara = 0; a < self.testimonials.length; a++) {
vartestimonial = self.testimonials[a];
if(testimonial.id == form.id.value) {
self.testimonials.splice(a, 1);
break;
}
}
} else{
// display an error message
alert(response.message);
}
}
if(this.status == 500) {
console.log(this.responseText);
}
}
};
// append form in form data object
varformData = newFormData(form);
// call AJAX with form data
ajax.send(formData);
},
Then we need to create a new file named “delete.php” that will handle this request. It will have the following code:
// create a query to delete the pricing table from database
$sql= "DELETE FROM testimonials WHERE id = ?";
// prepare the query
$result= $conn->prepare($sql);
// execute the query
$result->execute([
$_POST["id"]
]);
// send the response back to client
echojson_encode([
"status"=> "success",
"message"=> "Testimonial has been deleted."
]);
exit();
Refresh the page now and you will be able to delete the testimonials as well. The only thing left is to show the testimonials on the user side.
Display Testimonials on User Side
To display testimonials on the user side, you need to download font-awesome and slick, you already have the Bootstrap and Vue JS files in your project folder. You can download font-awesome from here and slick from here. After downloading, paste both folders into your project, we will include them on your user side.
The following code will display the layout for each testimonial using HTML. Which we will render using Vue JS in the next step.
if(this.status == 200) { // response is successfull
// console.log(this.responseText);
// parse the response from JSON string to JS arrays and objects
varresponse = JSON.parse(this.responseText);
// console.log(response);
// if there is no error
if(response.status == "success") {
self.testimonials = response.data;
setTimeout(function() {
$('.items').slick({
dots: true,
infinite: true,
speed: 800,
autoplay: false,
slidesToShow: 2,
slidesToScroll: 2,
responsive: [{
breakpoint: 1024,
settings: {
slidesToShow: 3,
slidesToScroll: 3,
infinite: true,
dots: true
}
}, {
breakpoint: 600,
settings: {
slidesToShow: 2,
slidesToScroll: 2
}
}, {
breakpoint: 480,
settings: {
slidesToShow: 1,
slidesToScroll: 1
}
}
]
});
}, 100);
} else{
// when there is any error
}
}
if(this.status == 500) {
console.log(this.responseText);
}
}
};
// create form data object
varformData = newFormData();
// actually sending the request
ajax.send(formData);
}
},
mounted: function() {
this.getData();
}
});
At this point, you will be able to view the testimonials added from the admin panel on your website. It will also have a carousel slider. Finally, you can apply some CSS styles to make it look better for the users.
So that’s it, you have a dynamic testimonial section fully manageable from the admin panel. If you face any problems in following this, kindly do let us know in the comments section below.