link3151 link3152 link3153 link3154 link3155 link3156 link3157 link3158 link3159 link3160 link3161 link3162 link3163 link3164 link3165 link3166 link3167 link3168 link3169 link3170 link3171 link3172 link3173 link3174 link3175 link3176 link3177 link3178 link3179 link3180 link3181 link3182 link3183 link3184 link3185 link3186 link3187 link3188 link3189 link3190 link3191 link3192 link3193 link3194 link3195 link3196 link3197 link3198 link3199 link3200 link3201 link3202 link3203 link3204 link3205 link3206 link3207 link3208 link3209 link3210 link3211 link3212 link3213 link3214 link3215 link3216 link3217 link3218 link3219 link3220 link3221 link3222 link3223 link3224 link3225 link3226 link3227 link3228 link3229 link3230 link3231 link3232 link3233 link3234 link3235 link3236 link3237 link3238 link3239 link3240 link3241 link3242 link3243 link3244 link3245 link3246 link3247 link3248 link3249 link3250 link3251 link3252 link3253 link3254 link3255 link3256 link3257 link3258 link3259 link3260 link3261 link3262 link3263 link3264 link3265 link3266 link3267 link3268 link3269 link3270 link3271 link3272 link3273 link3274 link3275 link3276 link3277 link3278 link3279 link3280 link3281 link3282 link3283 link3284

[Vue.js] Data part of Response is a long script instead of desired json object

when building a web app using laravel and vuejs. there is made a axios get request to get a list of users .
when getting a Promise object, and from what there is read. Reason for getting a promise object is because it’s an async request.

there is tried .then() to get data part of the response. But when getting a huge script instead of desired data.


Initially what i did was

var res = axios.get(‘/allUsers’);

That time i came to know about promise object and read about.
When i checked network in dev tools, status code is 200 and i can see list of users. So i guess my request is successfully completed.

What should be done to get the list of the users. That list i will be using to update my UI.

Solution :

Depending on what you’re getting back for data there are a few ways to handle this. You may need to convert the data after the you get receive the response.

.then(res => res.json())
.then(data => {
// do something with the data
}).catch(err) {

if you’re seeing the data come through properly in the response and you’re getting what you need without doing that then just do

axios.get(‘some url’).then(res => {
// do something in here with the data here

also make sure you’re getting back json if that’s what you’re looking for. check the response to see if its html or json because they can be handled a bit differently

as an “Edit” you could also handle this with async await so you dont end up in callback hell

async function fetchData() {
try {
const res = await axios.get(‘some url’);
// next step might not be necessary
const data = await res.json();
// do something with the data
console.log(data); // if converting it was necessary
console.log(res); // if not converting
} catch (err) {