Tagged: vue js ajax

Vue.js GET ajax request Fetch Data using PHP 0

Vue.js GET ajax request Fetch Data using PHP

Vue.js GET ajax request Fetch Data using PHP

In this Post We Will Explain About is Vue.js GET ajax request Fetch Data using PHP With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Vue.js GET ajax request with PHP (Fetching data) Example

In this post we will show you Best way to implement Vue.js Get JSON Data From MYSQL Database Using PHP, hear for how to retrieve data from mysql database in Vue.js with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Creating our Database

CREATE TABLE `students` (
  `studid` INT(11) NOT NULL AUTO_INCREMENT,
  `studentfname` VARCHAR(30) NOT NULL,
  `studentlname` VARCHAR(30) NOT NULL,
PRIMARY KEY(`studid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Inserting student Data into our Database

INSERT INTO `students` (`studid`, `studentfname`, `studentlname`) VALUES
(1, 'jaydeep', 'Gondaliya'),
(2, 'krunal', 'sisodiya');

Include External Libs

https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css

index.php

<!DOCTYPE html>
<html>
<body>
<div class="container">
	<h1 class="page-header text-center">Example of the Vue.js CRUD OPERATION with PHP and MySQLi</h1>
	<div id="students">
		<div class="col-xl-8 col-xl-offset-2">
			<div class="row">
				<div class="col-xl-12">
					<h2>Student List
					<button class="btn btn-success pull-right"><span class="live glyphicon glyphicon-plus"></span> Student</button>
					</h2>
				</div>
			</div>
			<table class="table table-bordered table-striped">
				<thead>
					<th>Student Firstname</th>
					<th>Student Lastname</th>
					<th>Action</th>
				</thead>
				<tbody>
					<tr v-for="stud in students">
						<td>{{ stud.studentfname }}</td>
						<td>{{ stud.studentlname }}</td>
						<td>
							<button class="live btn btn-success"><span class="live glyphicon glyphicon-edit"></span> student Edit</button> <button class="live btn btn-danger"><span class="live glyphicon glyphicon-trash"></span> Remove</button>
 
						</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>
<script src="vue.js"></script>
<script src="axios.js"></script>
<script src="main.js"></script>
</body>
</html>

api.php

<?php
 
$conn = new mysqli("localhost", "username", "password", "databasename");
 
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
 
$out = array('error' => false);
 
$crud = 'read';
 
if(isset($_GET['crud'])){
	$crud = $_GET['crud'];
}
 
 
if($crud = 'read'){
	$sql = "select * from students";
	$query = $conn->query($sql);
	$students = array();
 
	while($row = $query->fetch_array()){
		array_push($students, $row);
	}
 
	$out['students'] = $students;
}
 
 
$conn->close();
 
header("Content-type: application/json");
echo json_encode($out);
die();
 
 
?>

main.js

var main = new Vue({
	el: '#students',
	data:{
 
		students: []
	},
 
	mounted: function(){
		this.getAllStudents();
	},
 
	methods:{
		getAllStudents: function(){
			axios.get("api.php")
				.then(function(response){
					//console.log(response);
					main.students = response.data.students;
				});
		}
	}
});

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is How to get data from MySQL with Vue.js – PHP And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.