vue.js - vue-resource is not sending data to the php backend properly?
ringa_lee
ringa_lee 2017-06-15 09:22:37
0
3
717
// 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!

ringa_lee
ringa_lee

ringa_lee

reply all(3)
三叔

get request to pass parameters like this:

this.$http.get("get.php", { 
  params: {
    "a": 1,
    "b": 2
  }
}).

Reference https://github.com/pagekit/vu...

黄舟

This library is no longer officially recommended, use the axios one

学习ing

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template