Chapters
48 Chapters
|
5:05:52
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
24.
Ajax with Axios
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This course is also built to work with Vue 3!
What JavaScript libraries does this tutorial use?
// package.json
{
"devDependencies": {
"@symfony/webpack-encore": "^0.30.0", // 0.30.2
"axios": "^0.19.2", // 0.19.2
"bootstrap": "^4.4.1", // 4.5.0
"core-js": "^3.0.0", // 3.6.5
"eslint": "^6.7.2", // 6.8.0
"eslint-config-airbnb-base": "^14.0.0", // 14.1.0
"eslint-plugin-import": "^2.19.1", // 2.20.2
"eslint-plugin-vue": "^6.0.1", // 6.2.2
"regenerator-runtime": "^0.13.2", // 0.13.5
"sass": "^1.29.0", // 1.29.0
"sass-loader": "^8.0.0", // 8.0.2
"vue": "^2.6.11", // 2.6.11
"vue-loader": "^15.9.1", // 15.9.2
"vue-template-compiler": "^2.6.11", // 2.6.11
"webpack-notifier": "^1.6.0" // 1.8.0
}
}
9 Comments
just wondering why we
yarn add axios --dev. I thought the --dev meant you only want it in the dev environment. I see thatyarn help addsays it "save[s] package to yourdevDependencies" but I'm not really sure what that means in practical terms.Hey David,
Actually, all our JS dependencies are dev dependencies if you take a look at package.json file :) That's because technically there are dev deps, nothing is revealed to the user directly, everything is passed though Webpack Encore, i.e. precompiled by Webpack Encore, and technically Webpack Encore decides what to reveal to the end user. And so, it's not that much important where to put that JS dependency - into "dependencies" or in "devDependencies" section. You can do whatever you like, but you need to understand this concept with Webpack Encore. And it's kind of a good practice to put everything in devDependencies when you're handling your assets via Webpack Encore.
I hope this helps!
Cheers!
Yeah thank you. That's interesting indeed. Now I'm slightly less ignorant than I was a couple minutes ago!
Hey David,
Haha, great! :) But in short, that doesn't matter much and works both ways, depends on your preferences ;)
Cheers!
Hi guys.
I got an error at the last step:
`xhr.js:184 GET http://127.0.0.1:8000/api/products 500 (Internal Server Error)
createError.js:16 Uncaught (in promise) Error: Request failed with status code 500
Probably because of database connection:
hydra:description: "An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused"But locally via browser it works! http://127.0.0.1:8000/api/products
Any ideas?
Hey triemli!
Hmm, that's super weird. So.... if you browser to http://127.0.0.1:8000/api/products it works... but if you send an AJAX request to POST http://127.0.0.1:8000/api/products it fails with "Connection refused?". There should really be no difference between the two from an infrastructure standpoint: in both cases, your browser is making a web request to the same backend. Do you get this error consistently?
Cheers!
Actually mu fault, I didn't see the mmigrations there.
I created docker-compose yaml with:
Up it, made migrations and success xD
Ah sorry, misinformed a bit:
/api/products just page works. On json also connection refused:
` "@context": "/api/contexts/Error",
"@type": "hydra:Error",
"hydra:title": "An error occurred",
"hydra:description": "An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused",
"trace": [
But where it goes to connect?
Actually we don't up docker or any database services.
Ensure the database is there.
Update the .env with valid database connection information.
Afterwards load the fixtures.
php bin/console doctrine:fixtures:loadNow you can proceed (or at least I could)
"Houston: no signs of life"
Start the conversation!