search

Home  >  Q&A  >  body text

vue.js - vue-resource is not sending data to the php backend properly?

// 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_leeringa_lee2765 days ago729

reply all(3)I'll reply

  • 三叔

    三叔2017-06-15 09:24:37

    get request to pass parameters like this:

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

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

    reply
    0
  • 黄舟

    黄舟2017-06-15 09:24:37

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

    reply
    0
  • 学习ing

    学习ing2017-06-15 09:24:37

    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

    reply
    0
  • Cancelreply