DB access problems

J

JoeyP

I am new to perl.

I have built an AJAX app that works the way I want it. The app. has a
dynamic scroll list that displays inventory. Right now an array(hard
coded) fills a dynamic list.

I have placed the AJAX app. on a Linux server and can access it from
the web. It is now time for me to query the DB (which I am able to do
already), take that data and pass it to a JavaScript function that will
format the data for my array that will populate the list.

Problem: I don't know how to do that.

Questions: Do I have to build the HTML with statements like print
"<html>\n"; in my CGI?

Am I able to access the JavaScript and pass the data?

I guess I'm not sure about the layout and how to put it together. I
have read and searched online but have not found any examples for what
I want to do. I know there has to be plenty of these applications out
there.

Again, I am trying to query a DB on a Linux server. Use that data to
populate a dynamic scroll list in a HTML doc.

Any help/examples is appreciated. Thanks in advance.
 
J

JoeyP

Sherm said:
Good $DEITY no! That would defeat the purpose of using AJAX in the first
place. What you want to produce on the server is either XML or JSON, not
HTML. You then use JavaScript on the client to request the XML/JSON data,
and access the DOM to populate the list using the fetched data.

You should be sure to send the correct MIME type from your server script;
neither XML nor JSON is text/html!

JSON is easy to produce from a (possibly complex and/or deeply nested) Perl
data structure - have a look at the JSON module on CPAN.


The key is that it isn't just a single request, it's two or more. The first
request is for the empty HTML page. Additional requests are then made from
JavaScript, to fetch data in XML or JSON format and manipulate the page's
DOM to format that data.


You've *got* to be kidding. There are AJAX tutorials in abundance out there -
just google for "AJAX tutorial".

sherm--


I see. I'll check out the modules you mentioned. Your right, I have
found gangs of AJAX apps., I was just looking for a CGI I could
manipulate and get something working. Thanks again. I'll see what I can
find out about JSON module on CPAN.

Thanks again.
 
J

John Bokma

Sherm Pendley said:
I may have misinterpreted him, but I don't think the OP was asking
about that. Based on the "<html>\n" in his message, I think he was
asking if a complete, valid HTML document is required in response to
AJAX requests, and the answer to that is "no".

Yup true.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,608
Members
45,252
Latest member
MeredithPl

Latest Threads

Top