Untitled
unknown
plain_text
a year ago
1.7 kB
12
Indexable
// Wait until the document is fully loaded
$(document).ready(function(){
// Add a click event handler for the search button
$('#search_button').on('click', function() {
// Get the entered IP address
var ip_address = $('#ip_address').val();
// Ensure the IP address is not empty
if (ip_address === "") {
$('#user_info').html("<p style='color:red;'>Please enter an IP address.</p>");
return;
}
// AJAX request to the backend PHP script
$.ajax({
url: 'your_php_script.php', // Replace with your PHP script path
type: 'POST',
data: { ip_address: ip_address }, // Send the IP address
success: function(response) {
// Parse the JSON response from the server
var data = JSON.parse(response);
// Check if there is a "message" (no data found)
if (data.message) {
$('#user_info').html("<p style='color:red;'>" + data.message + "</p>");
} else {
// Display user details
var userInfo = '<p><strong>Name:</strong> ' + data[0].name + '</p>';
userInfo += '<p><strong>Email:</strong> ' + data[0].email + '</p>';
userInfo += '<p><strong>IP Address:</strong> ' + data[0].ip_address + '</p>';
$('#user_info').html(userInfo);
}
},
error: function() {
// Handle errors
$('#user_info').html("<p style='color:red;'>An error occurred while processing your request.</p>");
}
});
});
});Editor is loading...
Leave a Comment