Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tarang19's avatar

axios Request failed with status code null in native js

I am try to do communicate my vue nativescript application with Laravel(backend) using axios but when i try it will give me an error (Request failed with status code null)

my Axios query in nativescript App

 onItemTap(){
            let self = this;

            axios
    .get('https://localhost:8000/user/all', {
      timeout: 5000
    })
    .then(res => {  
        self.listOfItems = res.data
        console.log(self.listOfItems)
    })
    .catch(err => console.error(err));
        }
    },

and my laravel controller

public function index(Request $request)
    {
        $active_user = User::all();

        return $active_user;
    } 

All projects are runing on different ip network please help to solve my issue

0 likes
14 replies
tarang19's avatar

not use routes

my code


<template>
    <Page>
        <ActionBar title="Welcome to NativeScript-Vue!"/>
        <ListView for="item in listOfItems" @itemTap="onItemTap">
          <v-template>
            <!-- Shows the list item label in the default color and style. -->
            <Label>{{ item.title }}</Label>
          </v-template>
        </ListView>
    </Page>
</template>

<script >
    import axios from 'axios';
  export default {
    data() {
      return {
        msg: 'Hello World',
        listOfItems:null,
      }
    },

    mounted(){
        this.onItemTap()
    },
    methods:{
        onItemTap(){
            let self = this;

            axios
    .get('http://localhost:8000/user/all', {
      timeout: 5000
    })
    .then(res => {  
        self.listOfItems = res.data
        console.log(self.listOfItems)
    })
    .catch(err => console.error(err));
        }
    },
  }
</script>

<style scoped>
    ActionBar {
        background-color: #53ba82;
        color: #ffffff;
    }

    .message {
        vertical-align: center;
        text-align: center;
        font-size: 20;
        color: #333333;
    }
</style>
drewdan's avatar

Your laravel routes? For the route you are trying to hit?

tarang19's avatar

Route::get('user/all','UserController@index');

tarang19's avatar

Route::get('user/all','UserController@index');

drewdan's avatar

What gets returned in your network tab?

tarang19's avatar

http://127.0.0.1:8000/user/all

[{"id":1,"name":"Sinhgad Data Center","email":"[email protected]","avatar":"https:\/\/lh5.googleusercontent.com\/-J4UWflUadho\/AAAAAAAAAAI\/AAAAAAAAAAA\/AAKWJJN3ewKGIOmS1bVJc3SZLWhSyNvCMA\/photo.jpg"},{"id":2,"name":"tarang shah","email":"[email protected]","avatar":"https:\/\/lh3.googleusercontent.com\/a-\/AOh14GjJZ-HrxLjwjoFBZIGQuVMZrQ7LqUOV8s-nryHGTw"},
{"id":3,"name":"Tarang Shah","email":"[email protected]","avatar":"https:\/\/lh5.googleusercontent.com\/-6GkwxPfSZio\/AAAAAAAAAAI\/AAAAAAAAAAA\/AAKWJJPP4mW_7W_8iq2BUxC522TR_q3Lxg\/photo.jpg"},
{"id":4,"name":"sdc bakup","email":"[email protected]","avatar":"https:\/\/lh4.googleusercontent.com\/-9GQFjHgIFms\/AAAAAAAAAAI\/AAAAAAAAAAA\/AAKWJJMd-EgXicetxpV4Gv-v6fa6-OFWBA\/photo.jpg"},
{"id":5,"name":"tarang shah","email":"[email protected]","avatar":"https:\/\/lh3.googleusercontent.com\/-rUE5FqWm4z4\/AAAAAAAAAAI\/AAAAAAAAAAA\/AAKWJJMSydKxCwKIYXszos9v1tiPA5w7Uw\/photo.jpg"}]
drewdan's avatar

Is that the response from the axios call? If it is, it looks to be ok

tarang19's avatar

is necessary get records from passport Api or we can get directly from laravel project

drewdan's avatar

If your vue application is a separate project, then ideally you need to go via the api and use passport to protect the routes.

tarang19's avatar

do you have any link or working demo so i can see or any tutorial ?

Please or to participate in this conversation.