// js 代码
new Vue({
el: "#app",
data: {},
methods: {
get: function() {
this.$http.get("get.php", {
"a": 1,
"b": 2
}).then(function(res) {
alert(res.data);
}, function(res) {
alert(res.status);
})
}
}
})
----------
// php代码 (本人对PHP一无所知)
// 变量之前加上@是因为不加的话会报一个 undefined index :a的错
<?php
$a = @$_GET['a'];
$b = @$_GET['b'];
echo $a + $b
?>
After triggering the send event get, 0 is returned. In the example, 3 is returned. I have checked the code many times and it is exactly the same. Please solve it! Thanks!
get request to pass parameters like this:
This library is no longer officially recommended, use the axios one
The parameters of get should be added to the url, for example: get.php?a=1&b=2
This is the form of the parameters attached to the post method