Hey everyone,
I am tweaking a website to make it easier for employees to edit products. Right now, someone has to login to the DB and change prices, and then someone has to change the physical html of the website itself.
So I am writing code that pulls all the products off the DB, and displays them on a page which can be edited. I think doing everything with Ajax would be best.
ajaxRequest.open("GET", url, true); ajaxRequest.send(null);
The problem is, I only know how to process Ajax requests using a URL (using POST, GET, etc). I need help writing the code to pull the info off the DB, and display it.
The table name is PRODUCTS. Within PRODUCTS are the columns ID, STOCK, SHORTNAME, DESCRIPTION, PRICE and SHIPPING.
In the HTML, I have a div setup:
<div class="product">
<div class="productName">
SHORTNAME, PRICE, SHIPPING
</div>
<div class="productDesc">
ID, DESCRIPTION, STOCK
</div>
</div>
I want to set it up so if I click a button, ajax pulls all the information off PRODUCT, and creates .productName
div. If the user clicks .productName
, it will then further expand to reveal .productDesc
.
Question: How to I query the DB using AJAX on a button click, and put the information into elements?