Re: DB access problems



"JoeyP" <plantz.3@xxxxxxxxxx> writes:

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?

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.

I guess I'm not sure about the layout and how to put it together.

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.

have read and searched online but have not found any examples for what
I want to do.

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

sherm--

--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
.



Relevant Pages

  • Re: AJAX with embedded server questions
    ... another request is sent. ... ISTM that JSON tends to require less overhead for less structured ... discussion on the topic of XML vs. JSON. ... Prototype.js was written by people who don't know javascript for people ...
    (comp.lang.javascript)
  • Re: DB access problems
    ... That would defeat the purpose of using AJAX in the first ... What you want to produce on the server is either XML or JSON, ... data structure - have a look at the JSON module on CPAN. ... The key is that it isn't just a single request, ...
    (comp.lang.perl.misc)
  • Ajax Best Practice: Rendern der Daten
    ... Pattern am besten bei Ajax um? ... ich habe durch einen Ajax-Request Daten in Form von XML ... oder JSON zurückbekommen, so frage ich mich, wie man diese Daten nun ... auch Programmlogik und Ausgabe. ...
    (de.comp.lang.javascript)
  • Re: XML<-> JSON conversion. What do you think?
    ... JSON limitations... ... JSON is not XML. ... Converting one to the other literally will ... var attrs = node.attributes; ...
    (comp.lang.javascript)
  • Re: More bollocks from biggots
    ... The paper don't say that the best workaround is to use a XML ... A server can mount a defense against JavaScript Hijacking by responding ... on adding support for JSON in future versions. ...
    (comp.os.vms)