2018-06-27 09:06
浏览 107

Vue.js Axios.post向php发送变量,但我无法访问这些变量

I'm new to frontend development, and I'm facing a problem that I cannot resolve.

What I am trying to do is open a new popup HTML page with parameters (which I can pass as an array) by calling method from my vue.js file.

I googled possible solutions, but still could not find the source of the problem. Observing Chrome console, I suspect that works fine since it says:

data: "Array( [index_id] => 1 [log_id] => 63)…ow.print(); // });", status: 200, statusText: "OK", headers: {…}, config: {…}, …}

However, in the popup window, I cannot access the variables, or they are null.

The following code is a function in my vue.js:

printTransaction: function(index){
    // I have tried this but could not figure out
    // var formData = new FormData();
    // formData.append('index_id', index);
    //'/popup/popup_output_print.php', {
    //     index_id: index,
    // })
    // .then(function(response){
    // })
    // .catch(function(error) {
    //   console.error(error);
    // })

    // and this too :(
    const params = {
        index_id: index,
        log_id: logId,
    };'/popup/popup_output_print.php', params, {
        headers: {
            'content-type': 'application/json',
    .then(function(response) {;
    .catch(function(error) {

    let newWin ='/popup/popup_output_print.php');
    setTimeout(function() {
    }, 2000);

And this is the very first part of popup_output_print.php

<?php require("../_/inc/init.php");
    $data = json_decode(file_get_contents("php://input"), TRUE);
    $index_id = $data['index_id'];
    $log_id = $data['log_id'];

//Trying to print the value

    if($index_id == null) {
        echo "index_id is null";
    else {
        echo $index_id;

Then the popup window prints index_id is null

What am I doing wrong?

UPDATE: following the comment, I just tried var_dump, and the variables are all null. :(

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dpbz14739 2018-06-27 19:29

    What is going on is that have totally no effect to

    let newWin ='/popup/popup_output_print.php');

    this makes a GET request with no params.

    From my view, the better approach is to use something like Vue modal, i.e.:

    axios(...).then( response => openVueModal(

    If you prefer option, you can pass variables as a GET params:

    let newWin =`/popup/popup_output_print.php?index_id=${index}&log_id=${logId}`);

    You'll need to change backend then, to read vars from $_GET.

    Other solution might be to, put into window open template, so it request needed variables after opening.

    解决 无用
    打赏 举报

相关推荐 更多相似问题