Bonsai Project
Last updated
Last updated
The above request is a get request so we can add data to the url: 'name=Tom&age=10'
name
"Tom"
age
10
This is very useful as we can use it to pass data to another page.
For example you may want to do this: When a user clicks on a product, we go to the products detail page and display data for that product. But do not want to have to create a page for each product.
What we can do instead:
On product list page we redirect on a product button click
or just using an a link in the html
Notice our use of html query string '?id=1'. More info on query string
2. On the product.html page we need to get the query string from our url In the js page for it:
Note this is advanced: We would recommend instead of using js to create the elements you can copy and paste the html for the products and use js to update the name, price and the link to the product details page,
The js dom api can be used to insert html. The important methods are 'document.createElement' 'appendChild' and 'innerHTML' property
We could instead find an element and attach our new element as a child to it:
Or use innerHTML