473,651 Members | 2,630 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 2077
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
2143
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 processed? Thanks in advance, Stephan Maat
4
2037
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 using AJAX, so in my opinion this should also be possible using ATLAS, or can ATLAS just be used...
4
1383
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
2664
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 client, rather than doing page refreshes. I know there are a bunch of libraries out there...
3
3460
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 everything blows up because of the size of the array. Thats why im want to use an XML file (later i will...
10
3456
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 works fine when viewing it statically or with a META REFRESH header tag. The idea is to give the user...
2
2219
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 id = "page1"><form onaction = "step1.php" method="post">...</form></div>
4
5355
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 the application to go to the database retrieve a record and populate the fields.
0
8349
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8695
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8460
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5609
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.