'TypeError: b.split is not a function error
I'm trying to get data from MySQL via vue -> axios -> php. In response to the request, cath(error) fires with the following error:
TypeError: b.split is not a function
at index.js:1:1
at new Promise (<anonymous>)
at t.exports (index.js:1:1)
at t.exports (index.js:1:1)
at h.request (index.js:1:1)
at h.n.forEach.h.<computed> [as get] (index.js:1:1)
at Function.get (index.js:1:1)
at Vue.getDrivers (drivers.php:78:23)
at Vue.mounted (drivers.php:95:18)
at invokeWithErrorHandling (vue.js:1872:59)
in this file (drivers.php)
<script>
var app = new Vue({
el: '#newdriver',
data: {
drivers: [],
},
methods: {
getDrivers() {
axios.get({
url: 'scripts/drivers-action.php',
method: 'get',
})
.then((res) => {
console.log("result");
console.log(res);
this.drivers = res.data.rows;
})
.catch((error) => {
// handle error
console.log(error);
});
},
},
mounted: function() {
this.getDrivers();
},
});
</script>
drivers-action.php:
<?php
include('../dbcon.php');
$sql = "SELECT * FROM drivers";
$rows = getAllDrivers();
function getAllDrivers() {
$data = [];
$statement = $conn->prepare($sql);
if($statement->execute()) {
$data = $statment->fetchAll();
}
return $data;
}
$data = array('rows' => $rows);
echo json_encode($data);
?>
I can't figure out what is the problem and what is causing this error.
EDITED: dbconn.php, where i define $conn object for database connect
<?php
$conn = new mysqli(
'localhost',
'root',
'',
'beldum'
);
if($conn -> connect_error) {
die('Error: ('.$conn->connect_errno.')'.$conn->connect_error);
}
?>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
