Posted inProgramming / Ajax / php / VueJs

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




Example of the Vue.js CRUD OPERATION with PHP and MySQLi

Student List

Student Firstname Student Lastname Action
{{ stud.studentfname }} {{ stud.studentlname }}

api.php

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.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype