Я пытаюсь получить доступ и отправить данные со стороны PHP под названием buy.php на свой Javascript, и я получаю ошибку.
Ошибка при получении данных свойства: [TypeError: Не удалось проанализировать URL-адрес из buy.php]
Я проверил относительное местоположение, и оно все еще не работает:
// Fetch property data from PHP
function fetchPropertyData() {
fetch('buy.php') //
.then(response => response.json())
.then(data => {
// Log the fetched data to the console
console.log(data);
})
.catch(error => console.error('Error fetching property data:', error));
}
// Call the function to fetch property data when the page loads
fetchPropertyData();
Мой PHP-код:
$conn = new mysqli('localhost', 'root', '', 'realstate_main');
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Prepare SQL query to fetch all property details
$sql = "SELECT Email,phone,Address, Size,type, Price,location, Bedroom, Bathroom,listingfor,description,pictureURL FROM Sellhouse where address='lebu'";
$result = $conn->query($sql);
// Check if any properties are found
if ($result->num_rows > 0) {
// Fetch all property details
$properties = array();
while ($row = $result->fetch_assoc()) {
$properties[] = $row;
}
// Close database connection
$conn->close();
// Output property details in JSON format
echo json_encode($properties);
} else {
// No properties found
echo json_encode(['error' => 'No properties found']);
}
Подробнее здесь: https://stackoverflow.com/questions/785 ... om-buy-php