• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Migrating from tag-lib to AJAX call

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I've written a list display within a tag-lib that I am attempting to migrate to AJAX. The flow now consists of first displaying a search page and then dynamically inserting the list into the page after a search and allowing the browser to interpret it. This works fine, however, the list has an embedded tag which relies on another js call to determine if the record meets some criteria.

In the tag-lib I was able to get this js call to execute using the window dot on load method:


However, since the js is inserting the results it appears that the extra js call within the window dot on load never gets executed.

I can't put the call into the container page because the parameters for the js method are generated when the list is created.

Does anyone know of a way that I can force a js call when the AJAX returns the response?

Thanks a Million,
Graham
 
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Depends on how you are doing your Ajax. If you are using a smart library such as Prototype or jQuery, you can embed a script tag into the returned response and it will be executed when the response is added to the DOM.

Otherwise, not so easy...
 
graham king
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course I'm doing it the hard way...

Any suggestions?

Originally posted by Bear Bibeault:
Depends on how you are doing your Ajax. If you are using a smart library such as Prototype or jQuery, you can embed a script tag into the returned response and it will be executed when the response is added to the DOM.

Otherwise, not so easy...

 
Bear Bibeault
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by graham king:
Of course I'm doing it the hard way... Any suggestions?


Yes. Don't.

In this day and age, not using a library for your Ajax is borderline insane. There are so many nuances that these libraries take care of for you (embedded JavaScript being just one of them), that trying to do "raw Ajax" should be a committable offense.

So why are you doing it the "hard way"?
 
graham king
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd say lack of understanding towards the various libraries. As well I'm sort of a control freak when it comes to modifying and creating code. I like to get into the details of the code if it needs to be tweaked to get the results that are needed.

I wonder if I would be able to retro fit what I've done to harness the power of the prototype library?

I know I'm using the prototype library via a sourceforge project named "AJAX JSP Tag Library", but, again I'm not all that certain how to use it.

Originally posted by Bear Bibeault:

Yes. Don't.

In this day and age, not using a library for your Ajax is borderline insane. There are so many nuances that these libraries take care of for you (embedded JavaScript being just one of them), that trying to do "raw Ajax" should be a committable offense.

So why are you doing it the "hard way"?

 
Bear Bibeault
Sheriff
Posts: 67618
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by graham king:
I'd say lack of understanding towards the various libraries. As well I'm sort of a control freak when it comes to modifying and creating code.

I can understand that -- I've been told that I'm the same way. But, I still maintain that "raw Ajax" is like hitting yourself in the forehead with a ball-peen hammer. I recommend against it.

I wonder if I would be able to retro fit what I've done to harness the power of the prototype library?

For a quick learning curve and easy retro-fitting, I'd recommend jQuery over Prototype.
 
graham king
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
For a quick learning curve and easy retro-fitting, I'd recommend jQuery over Prototype.



Thanks Bear.
 
graham king
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
Depends on how you are doing your Ajax. If you are using a smart library such as Prototype or jQuery, you can embed a script tag into the returned response and it will be executed when the response is added to the DOM.

Otherwise, not so easy...



Bear, it looks like this is what you where talking about:



Updating your page dynamically with Ajax.Updater

Developers often want to make Ajax requests to receive HTML fragments that update parts of the document. With Ajax.Request with an onComplete callback this is fairly easy, but with Ajax.Updater it's even easier!

Suppose you have this code in your HTML document:

<h2>Our fantastic products</h2>
<div id="products">(fetching product list ...)</div>

The 'products' container is empty and you want to fill it with HTML returned from an Ajax response. No problem:

new Ajax.Updater('products', '/some_url', { method: 'get' });

That's all, no more work. The arguments are the same of Ajax.Request, except there is the receiver element in the first place. Prototype will automagically update the container with the response using the Element.update() method.

If your HTML comes with inline scripts, they will be stripped by default. You'll have to pass true as the evalScripts option in order to see your scripts being executed.



found here: http://www.prototypejs.org/learn/introduction-to-ajax

Thanks man!
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And then the JQuery way:

 
graham king
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by graham king:


found here: http://www.prototypejs.org/learn/introduction-to-ajax

Thanks man!



Works like a charm!!!



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic