How do I use Ajax and Jquery to pull information off a PHP database, and populate elements with that information? -


I'm tweaking a website so employees are easy to edit products. Now, someone has to enter DB and prices have to be changed, and then someone has to change the physical HTML of the website.

So I am writing code which pulls all the products from DB, and displays them on a page that can be edited. I think it would be best to do everything with Ajax.

ajaxRequest.open ("GET", URL, true); AjaxRequest.send (zero);

The problem is, I know about processing Ajax requests using only one URL (using POST, GET, etc). I need help in writing code for pulling information about DB, and displaying it.

The table name is the products within the column ID, stock, SHORTNAME, description, PRICE and shipping.

In HTML, I have a div setup:

   

I want to set it so that I can click on a button, AJAX pulls all information from PRODUCT, and creates .productName div I If the user clicks on .productName , then it will proceed to appear .productDesc .

Question: How can I ask DB by using AJX on one click, and insert information into elements?

Ajax can not access your database. Ajax simply loads the contents from the URL. Your application should do this, and the result must be provided in the form of an AJAX call.

How it will work here.

  1. Browser opens a URL on your server
  2. provides a page for display on PHP browsers
  3. User clicks a few
  4. Javascript sends an Ajax request to your server
  5. PHP receives this request and
  6. PHP provides a response to the request
  7. < Li> Ajax handler on your page gets this feedback as plain text and with it Something interesting happens (such as an inserted HTML, evaluation of JSON, or Javascript executed)

Ajax is actually a way to load a response from your browser without navigating to that page . It should not (and should not be) any kind of direct database access. In fact it is not known that there is a database at all.

Imagine the safety issues if any JavaScript can read or write any field in your database. This will be a hacker dream.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -