Board index » delphi » Ajax in Webbroker

Ajax in Webbroker


2008-02-24 06:27:12 PM
delphi18
I have been playing around with Ajax in my web broker apps lately. It is
pretty easy thanks to the Ajax toolkit from www.ajaxtoolkit.com In addition,
I have been looking for a way to replace internet express with a decent grid
as internet express does not work in Firefox and is incomplete and still
relegated to demo status in Delphi.
I have found a scrollable HTML table using Javascript here
www.webtoolkit.info/dhtml.html This works pretty well and, in
combination with Ajax it can make a pretty powerful master detail or combo
box solution without paying an arm and a leg for Intraweb.
One problem with XMLHttpRequest is that Javascript loaded in innerHTML is
not well supported in the browser, particularly in Firefox. The method that
I had been using, thanks to Marco Cantu, was this
function AjaxAboutUs()
{
AjaxRequest.get({
'url':'http://localhost/helene/about_us.html',
'onSuccess':function(req) {
document.getElementById('main-content').innerHTML =
req.responseText;
}
})
}
This works fine until the page being loaded into HTML contains form elements
or Javascript. One trap which caused me problems for many months was that
[table] [form] will not dispaly in Firefox but works fine in IE. The
solution is to replace it with [form][table] and then it works fine.
However, I have seen reports that some form elements do not behave correctly
in IE when using innerHTML.
In my app I have scrollable table of the master items with a link to get the
detail and display it in a div below. If the detail is in a scrollable table
which needs to run a javascript function it will render as a plain HTML
table, the Javascript to setup the table will only run in the body onload
event.
The answer to this problem and fixing the form problem is to write the
innerhtml to a javascript variable and then use the DOM appendchild method
to append it to the div. Here is an example.
function loaddetailtable()
{
AjaxRequest.get({
'url':'http://localhost/scrolltable/table3.html',
'onSuccess':function(req) {
var newdiv = document.createElement("teamtable");
newdiv.innerHTML = req.responseText;
var container = document.getElementById("table-3");
container.appendChild(newdiv);
}
})
}
This now works fine, but what happens when the user selects the next master
record? The function above will append the next detail table which will now
only display as plain HTML (appended to the previous table) because we have
a javscript conflict due to having 2 identical table IDs. We need first to
remove the previous element child and replace it with thenew one. Here is
the solution. This will now allow you to have a master table on your page
and write the detail table using Ajax and repalce it with the details of the
next master if needed.
function loaddetailtable()
{
AjaxRequest.get({
'url':'http://localhost/scrolltable/table3.html',
'onSuccess':function(req) {
var newdiv = document.createElement("teamtable");
newdiv.innerHTML = req.responseText;
var container = document.getElementById("table-3");
while (container.firstChild)
{container.removeChild(container.firstChild);}
container.appendChild(newdiv);
}
})
}
I thought I might post this here to encourage web broker users to use Ajax
in their apps and to provide a solution to anyone who encounters the same
problems as I did. There is really precious little written about these
problems that I could find so i hope this saves soembody some time.
Mark Horrocks
 
 

Re:Ajax in Webbroker

Hi Mark,
Thanks for sharing this! It would be nice if we could continue working
in our trusted environment while moving on to Ajax.
Is the link you gave (below) correct? I get a catchall page, unsure
where to go.
Tks,
Hans van Leth.
mark horrocks schreef:
Quote
I have been playing around with Ajax in my web broker apps lately. It is
pretty easy thanks to the Ajax toolkit from www.ajaxtoolkit.com
 

Re:Ajax in Webbroker

Sorry! Its here www.ajaxtoolbox.com/
It's really dead simple. Just add the ajaxrequest.js file to your site and
build a new js file I have appended some examples below to show usage. A
typical web site that I use is like this one at www.heleneintimates.biz
Typically you would want to have a page header and left menu bar stay the
same then replace the main content panel of your page. Just place a [div
id=main-content] [/div] construct in the appropriate place. The contents
will be replaced with the reponse from your server. So instead of returning
a full page you just need to return the panel content. For example in a div
id=login I might simply return the string "You are logged in as Mark
Horrocks" or a shopping cart to a div id=shopping cart. Search for marco
Cantu's excellent eample of how to use this for some extra stuff about XML
which I haven't used yet. As soon as I can figure out how to obtain the id
field from a selected HTML table row (xPath) I will replace all my Internet
Express pages with this.
Here are some examples. But ALWAYS use the mods I have described in posts
above to write innerHTML to a div and append the div to another div using
the DOM appendChild method. This will ensure that form elements and
Javascript work correctly. As yet I can not get Lighshow to work with this
technology, I am going to try Highslide.
These methods would write to any HTML element that has an id but I always
use a DIV element.
hth
Mark Horrocks
1. Returning simple html content
function AjaxAboutUs()
{
AjaxRequest.get({
'url':'www.heleneintimates.biz/about_us.html',
'onSuccess':function(req) {
document.getElementById('main-content').innerHTML =
req.responseText;
}
})
}
2. Returning content (get) from an ISAPI with parameters such as you would
normally use, like myISAPI.dll?sessid=123&anotherparameter=456
function GarmentsForSubmenu(x,y,z)
{
AjaxRequest.get({
'parameters':{'id':x,'page':y,'currency':z},
'url':'www.heleneintimates.biz/wholesale/wholesale.dll/garmentsForSubmenu',
'onSuccess':function(req) {
document.getElementById('main-content').innerHTML =
req.responseText;
}
})
}
3. Submitting form content to your ISAPI (post). Place the javscript
function call in the action method of your form.
function AjaxAddToCart(){
AjaxRequest.submit(orderform, {
'onSuccess':function(req) {
document.getElementById('shopping-cart').innerHTML =
req.responseText;
}
})
}
4. Submitting a form and returning a get request in the same action. In this
example the main panel of the page is replaced after login and a message is
written to another div advising that login was successful or not. This
writes to 2 separate areas of your page at the same time.
function AjaxCustomerLogin(){
AjaxRequest.submit(customerlogin, {
'onSuccess':function(req)
{document.getElementById('login-message').innerHTML = req.responseText;}
})
AjaxRequest.get({
'url':'www.heleneintimates.biz/default_content.html',
'onSuccess':function(req) {
document.getElementById('main-content').innerHTML =
req.responseText;
}
})
}
 

Re:Ajax in Webbroker

I have developed a demo application using the examples found in Marco
Cantu's Ajax Demo page at www.ajax.marcocantu.com It demontrates the use of
the Ajax toolkit with XSLT and XML. However, there are some problems I can't
figure out.
It is at www.sportdata.com.au/xml/default.html It works perfectly in Firefox
but not at all in internet explorer. Marco Cantu's site does work in
internet explorer. I get no error messages at all in either Firefox or
Internet Explorer.
Also, the Google Ajax-XSLT toolkit that marco used was version 0.4 dated
October, 2005. The latest version is now 0.8 recently released. The new
version works fine on localhost but throws errors when loaded on my 2003
server. (XML10_Name is not defined) If I revert to version 0.4, the same as
Marco used, it works fine. (on Firefox).
The data comes from my ISAPI and works with cds.XMLData but I found that
it's better to format the data in Delphi (like currencies and dates) as
finding the XPath functions to do this are beyond me.
Feel free to download and play with the code. It downloads XML and does an
XSL transform on the request, then saves a copy of the xml in a textarea
(hidden) as a local cache. Then if you click the view button after selecting
a record, it uses XPathEval to search the XML and locate the relevant
record, does a transform on the record and displays it using Ajax. The demo
uses 3 levels of master detail.
If anybody has the time and inclination to figure out
1. Why the latest Google Ajax-SLT toolkit does not work on 2003 server.
2. Why this code does not work in Internet Explorer
I would be most grateful. Users of webbroker should find this stuff very
useful.
Mark Horrocks
 

Re:Ajax in Webbroker

I fixed the Internet Explorer problem. The XML datapacket need to be
prepended with "tag" ?xml version="1.0" standalone="yes"? "end tag". Firefox
was happy without it but Bill got a bit annoyed.
Still don't know about why the latest Google tookit hates me.
Mark Horrocks
 

Re:Ajax in Webbroker

For the client side look at jquery javascript library. You can write ajax
applications without worring about IE or safari or Firefox diferences.
isapi + xml + jquery is a very very powerfull combination.
Francisco Ruiz
 

Re:Ajax in Webbroker

On Apr 18, 5:54 pm, "Francisco Ruiz" <XXXX@XXXXX.COM>writes:
Quote
For the client side look at jquery javascript library. You can write ajax
applications without worring about IE or safari or Firefox diferences.

isapi + xml + jquery is a very very powerfull combination.

Francisco Ruiz
Prototype and Scriptaculous are also good candidates for the client
side, as well as Yahoo's YUI library and Ext-JS.
Also, take a look at JSON for;at for the communication, it is much
more compact than XML and can be directly evaluated to Javascript.
On the json.org website there is a list of libraries, including a
couple of Delphi ones.
Good luck:)
Marius Popescu
pcpal.eu