473,544 Members | 2,340 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript as AJAX response (RPC)

Hi,

Some servers return JavaScript as the response to an AJAX request. When
the response JavaScript is eval'ed it calls other JavaScript functions
already in the browser to update elements, etc. This seems like a good
system because it allows so much freedom in creating the desired
behavior in the browser. The required data doesn't have to be converted
to XML or JSON on the server. The browser doesn't have to have
templates for interpreting and converting this data into some change in
the browser. All of the conversion algorithms don't have to be written
and changed when new behavior is required. This remote procedure call
approach is the predominant system in the Ruby on Rails world.
(Unfortunately they are calling Prototype.js functions.)

However apparently some people seem to think this remote procedure call
approach is a bad idea. I can't see why it is so bad because it is so
lightweight and flexible. It also helps to keep the client less
intellegent which seems good in a world of incompatible client-side
bugs.

If I use some neutral data format like XML to accomdate different types
of clients then I have to write different client-side interpreters for
each type of client (browser, RSS, POP, cell phone, etc). Why not just
write different server-side code that generates the correct JavaScript
(or other) for the requesting client type?

When is the RPC approach such a bad idea?

Thank you,
Peter

Oct 15 '06 #1
5 2072
Some servers return JavaScript as the response to an AJAX request.
When is the RPC approach such a bad idea?
One problem I see with this approach is the need to change the API you are
calling. You limit your refactoring choices if you need to keep the new API
call backwards-compatible, and you may run into trouble when changing
versions.
The other issue is that you have a relatively high coupling between server
and client code across language boundaries, which is not always desirable.
Having said that, I also like this type of "RPC" calls. In my shop we use it
for one of our products. So far we haven't had any problems.
OTOH, we have a very small codebase for this product, and we use only one
AJAX request with a choice of server code (PHP, ASP, Java). In our setting
this works quite ok without too much hassle.
For large codebases with lots of different AJAX requests, though, I would
recommend to use this approach with extreme caution. You may be better off
with a data-centric approach here. But, then, I'd recommend extreme caution
for any kind of programming technique. There is no such thing as fool-proof.

Regards,
Leo

Oct 15 '06 #2
Hi,

pe**********@gm ail.com wrote:
Hi,

Some servers return JavaScript as the response to an AJAX request. When
the response JavaScript is eval'ed it calls other JavaScript functions
already in the browser to update elements, etc. This seems like a good
system because it allows so much freedom in creating the desired
behavior in the browser. The required data doesn't have to be converted
to XML or JSON on the server. The browser doesn't have to have
templates for interpreting and converting this data into some change in
the browser. All of the conversion algorithms don't have to be written
and changed when new behavior is required. This remote procedure call
approach is the predominant system in the Ruby on Rails world.
(Unfortunately they are calling Prototype.js functions.)

However apparently some people seem to think this remote procedure call
approach is a bad idea. I can't see why it is so bad because it is so
lightweight and flexible. It also helps to keep the client less
intellegent which seems good in a world of incompatible client-side
bugs.

If I use some neutral data format like XML to accomdate different types
of clients then I have to write different client-side interpreters for
each type of client (browser, RSS, POP, cell phone, etc). Why not just
write different server-side code that generates the correct JavaScript
(or other) for the requesting client type?

When is the RPC approach such a bad idea?

Thank you,
Peter
The main issue I have with this approach is that you limit yourself to a
JavaScript client. Moreover, probably you limit yourself to a web
browser based JavaScript client.

Web services (in the broad sense of the word) should be, IMHO,
"universall y" callable. We are only starting to see RIAs (rich internet
applications) calling all kind of web services (SOAP based, POX based
(plain old XML), etc...) to enhance the user experience. If you publish
a JavaScript-only web service, you close your door to such applications.
Additionally, if you want to open the door, the refactoring effort will
be huge.

I prefer standard interfaces when possible, i.e. SOAP or POX. In .NET
2.0 applications (ASP.NET, WinForms, WPF), for example, integrating SOAP
based web services is ridiculously easy. It means that a lot of
programmers will do so. As a web service provider, you have "duties" to
them (just like an interface is a "contract") . IMHO the duties are:
don't add breaking changes to your interface; make the interface easy to
use; make the interface as universal as possible.

Of course there are exceptions to that "rule" (of thumb ;-), but more
than often an interface designed for one single application ends up
being reused in other apps as well. If you choose standard to start
with, the refactoring will be easier.

HTH,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
Private/Malaysia: http://mypage.bluewin.ch/lbugnion
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 16 '06 #3
Laurent Bugnion <ga*********@bl uewin.chwrote:
The main issue I have with this approach is that you limit yourself to a
JavaScript client. Moreover, probably you limit yourself to a web
browser based JavaScript client.

Web services (in the broad sense of the word) should be, IMHO,
"universall y" callable.
Who was talking about web services? This was a question about AJAX.

--
Chris Smith
Oct 16 '06 #4
<pe**********@g mail.comwrote:
Some servers return JavaScript as the response to an AJAX request. When
the response JavaScript is eval'ed it calls other JavaScript functions
already in the browser to update elements, etc.
Okay.
However apparently some people seem to think this remote procedure call
approach is a bad idea. I can't see why it is so bad because it is so
lightweight and flexible.
If I'm understanding your approach properly, the main disadvantage is
that you are introducing high levels of coupling between the user
interface and the server-side implementation code. If that's not
important to you, then great. In many cases, though, it's nice to be
able to redesign a web page without needing to go through the
implementation of four or five different asynchronous requests it makes,
just to make conforming changes. With the more traditional approach,
the code to update the web page is in JavaScript code that's inside or
stored near the client-side page itself.

That said, there are other ways of approaching a solution to the
coupling problem. For example, using a component-based environment
(something like JavaServer Faces) for developing the server-side code
may allow you to ensure that the changes to server and client are made
in synch and reduce coupling, without needing to abandon this general
technique.

--
Chris Smith
Oct 16 '06 #5
Hi,

Chris Smith wrote:
Laurent Bugnion <ga*********@bl uewin.chwrote:
>The main issue I have with this approach is that you limit yourself to a
JavaScript client. Moreover, probably you limit yourself to a web
browser based JavaScript client.

Web services (in the broad sense of the word) should be, IMHO,
"universally " callable.

Who was talking about web services? This was a question about AJAX.
Which is why I wrote "in the broad sense of the word". Web services as
services exposed on the web. I think I made it clear in my answer that I
was also talking about POX.

Greetings,
Laurent
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Oct 16 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2138
by: sgmaat | last post by:
I have create a AJAX webpage where if you press a link content is loaded into a div. NOw when this content is loaded no javascript is processed (i.e <Script>alert(..);</script>), but if the javascript is in <a onclick="..."> it will work. What i would like to know is: - Is this normal - What do i need to change so that javascript does get...
4
2031
by: s.bussing | last post by:
Hi All, I'm new to Atlas and I did some programming using AJAX, but I'm wondering if it is possible to hava a javascript which can call a server-site function, in my case to write data to the cache, using AJAX. So I'm not looking for a possibility to wrap-up controls, but just to call server-site code from ATLAS. I know this can be done...
4
1379
by: Barry | last post by:
Hi i have the following class Public Class ShipmentClass Public RatedShipment As RatedShipmentClass() Public Class RatedShipmentClass Public GuaranteedDaysToDelivery As String Public ScheduledDeliveryTime As String Public Code As String
10
2654
by: Tom Cole | last post by:
While I've done javascript work for as long as I can remember (since Netscape first released it), I've only ever used it for trivial things, change a color here, validate a text element there, blah blah blah. With Ajax (actually, the uncovering of the XmlHTTPRequest object) I absolutely see the benefit of moving more of the UI work to the...
3
3449
by: SM | last post by:
Hello, Im trying to access elements in my XML file using the JavaScript DOM but i'm not sure how. I use AJAX to access the XML and then use the responseXML property to access the XML file data. I want to extract all the tracks from a specific CD. Right now, im using an array to stock all the data but its just a question of time before...
10
3432
by: paulie | last post by:
Hi, I have been experiencing an issue when trying to use AJAX to reload a DIV area using a timer of 2000ms, which contains a html page with another DIV and javascript. Scenario ------------- I have perl script which simply runs a ps on a Solaris server and generates a static html page with all of the code perfectly and this html page...
2
2212
by: Ronald Raygun | last post by:
I have a form that I am using as a wizard. The wizard comprises of several forms contained in divs, which are hidden/made visible, depending on the wizard step. Each form has an action parameter set to a different php script, which is responsible for returning a true/false (+ mesage back to the form. So I have something like this: <div...
4
5347
by: Peter | last post by:
ASP.NET I have an application which use ASP.NET Autocomplete extender which works great. But I have a question how to update all the fields on the screen using Ajax. Users starts typing in a text field which causes the Autocomplete extender to display 10 like items, after the users selects an item (which is a key in the database) I want...
0
7642
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7796
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7405
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7737
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5316
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4938
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3432
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1861
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.