Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can';无法使用VueJs从Mysql数据库获取数据_Javascript_Php_Mysql_Vue.js_Axios - Fatal编程技术网

Javascript Can';无法使用VueJs从Mysql数据库获取数据

Javascript Can';无法使用VueJs从Mysql数据库获取数据,javascript,php,mysql,vue.js,axios,Javascript,Php,Mysql,Vue.js,Axios,我试图通过前端的{orderdtls.id}使用vuejs和axios从mysql数据库获取数据,但数据响应为null。 我还检查了我的php代码,但没有发现任何问题,php代码本身工作正常 PHP代码: header('Access-Control-Allow-Origin: *'); header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE'); header('Access-Contr

我试图通过前端的
{orderdtls.id}
使用vuejsaxios从mysql数据库获取数据,但数据响应为
null
。 我还检查了我的php代码,但没有发现任何问题,php代码本身工作正常

PHP代码:

    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE');
    header('Access-Control-Allow-Headers: X-Requested-With,Origin,Content-Type,Cookie,Accept');
    $Catch_Query = json_decode(file_get_contents("php://input"));

 if($Catch_Query->action == 'fetchdata'){
    
              $orderid = $_GET['uniqid'];
              $getorder = "SELECT * FROM ordertbl WHERE uniqid='$orderid'";
              $order_query = $con->query($getorder);
              $order_init = $order_query->fetch_assoc();
              $Order_detalis = array();

              $Order_detalis[] = $order_init;
              echo json_encode($Order_detalis);
           
            }
var OrderInfo = new Vue({
            el: '#rdp',
            data:{
                orderdtls:'',
            },
            methods:{
                fetchOrderDtls:function(){
                    axios.post(BaseUrl + '/core/core.php', {action:'fetchdata'}).then((response) => {
                        OrderInfo.orderdtls = response.data;
                        console.log(response);
                    }).catch(function(errors){
                        console.log(errors);
                    });
                }
            },
            created(){
                this.fetchOrderDtls();
            }


    });
{data: "", status: 200, statusText: "", headers: {…}, config: {…}, …}
config: {url: "https://example.com/core/core.php", method: "post", data: "{"action":"fetchdata"}", headers: {…}, transformRequest: Array(1), …}
data: ""
headers: {access-control-allow-headers: "X-Requested-With,Origin,Content-Type,Cookie,Accept", access-control-allow-methods: "GET, POST, OPTIONS, PUT, DELETE", access-control-allow-origin: "*", content-length: "0", content-type: "text/html; charset=UTF-8", …}
request: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}
status: 200
statusText: ""
__proto__: Object
Vue脚本:

    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE');
    header('Access-Control-Allow-Headers: X-Requested-With,Origin,Content-Type,Cookie,Accept');
    $Catch_Query = json_decode(file_get_contents("php://input"));

 if($Catch_Query->action == 'fetchdata'){
    
              $orderid = $_GET['uniqid'];
              $getorder = "SELECT * FROM ordertbl WHERE uniqid='$orderid'";
              $order_query = $con->query($getorder);
              $order_init = $order_query->fetch_assoc();
              $Order_detalis = array();

              $Order_detalis[] = $order_init;
              echo json_encode($Order_detalis);
           
            }
var OrderInfo = new Vue({
            el: '#rdp',
            data:{
                orderdtls:'',
            },
            methods:{
                fetchOrderDtls:function(){
                    axios.post(BaseUrl + '/core/core.php', {action:'fetchdata'}).then((response) => {
                        OrderInfo.orderdtls = response.data;
                        console.log(response);
                    }).catch(function(errors){
                        console.log(errors);
                    });
                }
            },
            created(){
                this.fetchOrderDtls();
            }


    });
{data: "", status: 200, statusText: "", headers: {…}, config: {…}, …}
config: {url: "https://example.com/core/core.php", method: "post", data: "{"action":"fetchdata"}", headers: {…}, transformRequest: Array(1), …}
data: ""
headers: {access-control-allow-headers: "X-Requested-With,Origin,Content-Type,Cookie,Accept", access-control-allow-methods: "GET, POST, OPTIONS, PUT, DELETE", access-control-allow-origin: "*", content-length: "0", content-type: "text/html; charset=UTF-8", …}
request: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}
status: 200
statusText: ""
__proto__: Object
这是控制台日志:

    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE');
    header('Access-Control-Allow-Headers: X-Requested-With,Origin,Content-Type,Cookie,Accept');
    $Catch_Query = json_decode(file_get_contents("php://input"));

 if($Catch_Query->action == 'fetchdata'){
    
              $orderid = $_GET['uniqid'];
              $getorder = "SELECT * FROM ordertbl WHERE uniqid='$orderid'";
              $order_query = $con->query($getorder);
              $order_init = $order_query->fetch_assoc();
              $Order_detalis = array();

              $Order_detalis[] = $order_init;
              echo json_encode($Order_detalis);
           
            }
var OrderInfo = new Vue({
            el: '#rdp',
            data:{
                orderdtls:'',
            },
            methods:{
                fetchOrderDtls:function(){
                    axios.post(BaseUrl + '/core/core.php', {action:'fetchdata'}).then((response) => {
                        OrderInfo.orderdtls = response.data;
                        console.log(response);
                    }).catch(function(errors){
                        console.log(errors);
                    });
                }
            },
            created(){
                this.fetchOrderDtls();
            }


    });
{data: "", status: 200, statusText: "", headers: {…}, config: {…}, …}
config: {url: "https://example.com/core/core.php", method: "post", data: "{"action":"fetchdata"}", headers: {…}, transformRequest: Array(1), …}
data: ""
headers: {access-control-allow-headers: "X-Requested-With,Origin,Content-Type,Cookie,Accept", access-control-allow-methods: "GET, POST, OPTIONS, PUT, DELETE", access-control-allow-origin: "*", content-length: "0", content-type: "text/html; charset=UTF-8", …}
request: XMLHttpRequest {readyState: 4, timeout: 0, withCredentials: false, upload: XMLHttpRequestUpload, onreadystatechange: ƒ, …}
status: 200
statusText: ""
__proto__: Object

编辑:聊天讨论显示301重定向导致负载未到达服务器路由。下面的答案仍然有效


代码需要在数据库调用的数据对象中传递一个
uniqid
。另外,
$\u GET
将为空,因为您正在执行axios
post
而不是
GET

uniqid
与其他数据一起传递:

axios.post(BaseUrl+'/core/core.php'{
操作:'fetchdata',
uniqid:1//{
OrderInfo.orderdtls=response.data;
控制台日志(响应);
}).catch(函数(错误){
console.log(错误);
});
在PHP后端,从存储在
文件\u get\u contents
中的post数据中获取此
uniqid

if($Catch\u Query->action==“fetchdata”){
$orderid=$Catch\u Query->uniqid;
...
}

哪里是
$\u GET['uniqid']
来自?应该是undefined@Dan它来自url中的一个变量,如example.com/page.php?uniqid=123@Danuniqid显示在页面url中,我认为当php文件执行时,if语句的主体也将被执行,
$orderid
将使用uniqid填充。我在php文件中手动设置uniq id,但没有任何更改。Lo再次查看您的Vue代码。在您
axios.post
的url中没有
uniqid
。我发布了一个答案来向您展示。当您手动设置时,当您
var_dump($order_init)
时,您会看到什么?@Dan Nothing,甚至不
NULL
它无论如何都应该为NULL,我怀疑语句是否未执行。。