473,387 Members | 1,760 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

inline function with ajax to set a property

I'm creating a simple AJAX library. It's an object that will return an
array containing the response text or xml. I'm trying to find a way to
assign the response as a property of the object, but from within an
inline function.

Within the AJAX object:
this.xmlhttp = new XMLHttpRequest();
this.response = ''; //to contain the response text OR xml

var that = this; //since we cannot reference this within the
//following inline function

this.xmlhttp.onreadystatechange = function() {
if (that.xmlhttp.readyState==4) {
// if "OK"
if (that.xmlhttp.status==200) {
if(that.xmlhttp.responseXML)
that.response = that.xmlhttp.responseText;
else
that.response = that.xmlhttp.responseText;
}
else {
alert("Problem retrieving XML data")
}
}
};

The problem is that the response isn't getting set within the Ajax
object (by copying the object reference). I'm trying to figure out a
way to set this property into the Ajax object. However, not much
experience in inline functions. Thanks,

-Eric

Nov 2 '05 #1
4 4275
bobzimuta wrote:
I'm creating a simple AJAX library. It's an object that
will return an array containing the response text or xml.
I'm trying to find a way to assign the response as a
property of the object, but from within an inline function.
An 'inline' function is not usual terminology. You either mean a
function expression or an inner function. Assuming the code below is
wrapped in a function then the onreadystatechance handler is both a
function expression and an inner function.
Within the AJAX object:
this.xmlhttp = new XMLHttpRequest();
this.response = ''; //to contain the response text OR xml

var that = this; //since we cannot reference this within the
//following inline function
I would not use 'that' as the identifier for the object itself, but
'that' is not a keyword so should not actually be a problem.
this.xmlhttp.onreadystatechange = function() {
if (that.xmlhttp.readyState==4) {
// if "OK"
if (that.xmlhttp.status==200) {
if(that.xmlhttp.responseXML)
that.response = that.xmlhttp.responseText;
else
that.response = that.xmlhttp.responseText;
I cannot see much point in branching based on the true-ness of
that.xmlhttp.responseXML and then assigning that.xmlhttp.responseText in
both branches.
}
else {
alert("Problem retrieving XML data")
}
}
};
That should work, assuming the surrounding code is as I would expect
(and that the order of calling open, assigning the handler and calling
send, is correct).
The problem is that the response isn't getting set within
the Ajax object (by copying the object reference).
If the object you are referring to here is the responseXML then the fact
that you never assign it to the response may explain that (also, the
availability of responseXML depends quite a lot on the incoming XML
being correctly packaged).
I'm trying to figure out a
way to set this property into the Ajax object.
You might need to provide a wider context because (apart from as noted)
the above should do what it was coded to do.
However, not much
experience in inline functions. Thanks,


<URL: http://www.crockford.com/javascript/private.html >
<URL: http://www.jibbering.com/faq/faq_notes/closures.html >

Richard.
Nov 2 '05 #2
Hello Eric,

Sorry for contacting you on an unsolicited basis, but I've read a few
of your posts on
comp.lang.javascript. I'm a journalist with Application Development
Trends (ADT, http://www.adtmag.com) and I'm working on a story on AJAX.
(Will wonders never cease, eh?)

If you don't mind, I'd like to ask you a few questions about your use
of/interest in AJAX. If you would be willing to answer a few questions
via e-mail, I'd very much appreciate it. I've appended some questions
below, and I'd ask that you answer as many (or as few) as you wish.
Don't worry about answering all of them (although, hey, that would be
fantastic :) -- just tackle the ones about which you have the most to
say.

In addition, I can quote you any way you like, so if your employer
doesn't want its name used in print, I'll be more than happy to
obfuscate its identity. Or your own, too, if you would prefer.

Thanks very much. Appreciate your time and trouble, and I apologize,
again, for contacting you on an unsolicited basis.

Best,

Steve

1. If you're working with AJAX, what kinds of (business) problems are
you using the AJAX vision/concept to try to solve? What other
products/technologies/methods have you explored, and why or why do you
not think AJAX' asynchronous JavaScript-based model is a potential
solution?

2. AJAX isn't the first spin on asynchronous remote scripting. If I
recall correctly, Microsoft introduced Remote Scripting several years
ago, after all. But Microsoft's implementation was plagued by security
problems. (I can't be bothered to look -- not right now, at least --
but I believe I can remember at least one Remote Scripting-specific
exploit for Windows NT 4.0 or Windows 2000.) As far as security is
concerned, what makes AJAX any different?

3. The "X" in AJAX stands for XML. As I understand it, however, you
don't necessarily have to use XML to "do" what is called AJAX. (AJAX,
as I understand it, describes the concept of having JavaScript
communicate directly with a server without first reloading HTML.) At
the same time, one of the most popular ways of "doing" AJAX seems to be
with the XMLHttpRequest, which -- as the "X" in AJAX indicates -- seems
to have become synonymous with the technology. So...do most of the AJAX
solutions you're aware of/have worked with use XML (or XMLHttpRequest)?
Are you aware of any approaches to doing AJAX that don't involve XML?
Can you think of any benefits or drawbacks associated with either
approach? (For example, why is the (non-standard) XMLHttpRequest one of
the most popular ways of doing what is called AJAX?)

4. Similarly, isn't there a sense in which smart developers have been
using AJAX-like approaches since before AJAX was explicitly identified?
Haven't programmers who care about application performance issues
(e.g., load times, quality-of-experience for end users) long been
"circum-coding," as it were, the inherent limitations of the
conventional HTTP client request model? If so, what approaches have
they used? Why is or why isn't AJAX any better?

5. There's a sense in which XML could actually be a hindrance -- if,
for example, you're using XMLHttpRequest to send large amounts of data
between a JavaScript client and server. Is this a potential limiting
issue for the AJAX vision, or is it largely a *non* issue (apps that
need to exchange large amounts of data by definition won't do so using
JavaScript, but -- instead -- by some other, more robust means)? I'm
leaning toward the latter understanding, mainly because AJAX seems to
describe a way to exchange *new*, *changed* or otherwise *requested*
data (i.e., rather than reloading the whole page, the HTTPD just sends
the data that the client requests.)

6. AFAIK, XMLHttpRequest isn't currently standardized, even though it's
supported by all major browsers. There are other concerns, too, in that
AJAX methods don't always conform to expected browser behaviors. (e.g.,
WikiPedia says "it might easily break the expected behavior of the
browser's back button.") Are thesee potential issues? Are they mostly
overblown?

7. Not sure if you've already addressed this issue in your
pros-or-cons-of-AJAX responses, but I've read some folks in different
newsgroups who say that the AJAX vision does away with some of the
biggest pain points associated with Java applets, namely, performance
issues and UI kludginess. (As one poster put it, because AJAX basically
consists of HTML, JavaScript, and CSS, "you can resize windows and
expect to see text and tables wrapped and presented in all the normal
ways.") Is the UI kludginess of Java aplets a significant issue, from
your perspective, or have you and other developers largely licked this
problem?

8. I wanted to ask some questions about AJAX and Microsoft's .NET
development universe. I'm aware of several thriving AJAX for .NET
solutions/sites/communities, but I'm wondering if the inimical
opposition of J2EE and .NET often precludes the use or adoption of
AJAX-like approaches in the Microsoft universe? Is AJAX such a good
idea that it's also taking root (or will take root) among .NET
developers, too? Or -- perhaps more to the point -- has JavaScript
become such a generic technology that it more or less transcends the
divisions of J2EE vs. .NET? And does Microsoft have an AJAX-like (but
..NET-centric) technology vision of its own?

Nov 23 '05 #3
"daedalus" <st************@gmail.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...

[snip]
6. AFAIK, XMLHttpRequest isn't currently standardized


Correct; however: http://www.w3.org/2006/webapi/

[snip]
Nov 23 '05 #4
daedalus said the following on 11/18/2005 4:54 PM:
Hello Eric,

Sorry for contacting you on an unsolicited basis, but I've read a few
of your posts on
comp.lang.javascript. I'm a journalist with Application Development
Trends (ADT, http://www.adtmag.com) and I'm working on a story on AJAX.
(Will wonders never cease, eh?)


Who is Eric?
And, why don't you email him instead? (Whoever he is).
The groups FAQ is listed below, it should provide some good reading.

P.S. This "AJAX" stuff is way over-rated.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 23 '05 #5

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

Similar topics

1
by: StumpY | last post by:
Hi I have a code which works ok, except I would like to load the specified file in an inline frame (I1) on the page instead of a whole new page if at all possible - any help appreciated! Here is...
46
by: DJ WIce | last post by:
Hi all, I did make a script/css thing to replace the contextmenu on the website with a new one: http://www.djwice.com/contextmenu.html It works nice in MSIE, but on Netscape (and probable...
18
by: Method Man | last post by:
If I don't care about the size of my executable or compile time, is there any reason why I wouldn't want to inline every function in my code to make the program run more efficient?
12
by: JMB | last post by:
Hello, I was wondering if anyone knew of any projects extending the inline upload progress bar to utilize an inpage image uploader with bar, without having to refresh or go to a seperate page,...
33
by: Robert Seacord | last post by:
When writing C99 code is a reasonable recommendation to use inline functions instead of macros? What sort of things is it still reasonable to do using macros? For example, is it reasonable to...
0
by: =?Utf-8?B?R3JlZyBQZXRlcnM=?= | last post by:
With Visual Studio 2008 ASP.NET, I am using an inline AJAX CalendarExtender, followed by an inline AJAX DropDownExtender that extends a label contol. After selecting a date via the calendar...
3
by: pjdelaere | last post by:
Hi, In a multiuser environment the following happens: for one user I load a page that contains external, internal and inline javascript; all runs well. If I load new internal or inline...
17
by: Juha Nieminen | last post by:
As we know, the keyword "inline" is a bit misleading because its meaning has changed in practice. In most modern compilers it has completely lost its meaning of "a hint for the compiler to inline...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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,...
0
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...

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.