473,699 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.on readystatechang e = function() {
if (that.xmlhttp.r eadyState==4) {
// if "OK"
if (that.xmlhttp.s tatus==200) {
if(that.xmlhttp .responseXML)
that.response = that.xmlhttp.re sponseText;
else
that.response = that.xmlhttp.re sponseText;
}
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 4321
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 onreadystatecha nce 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.on readystatechang e = function() {
if (that.xmlhttp.r eadyState==4) {
// if "OK"
if (that.xmlhttp.s tatus==200) {
if(that.xmlhttp .responseXML)
that.response = that.xmlhttp.re sponseText;
else
that.response = that.xmlhttp.re sponseText;
I cannot see much point in branching based on the true-ness of
that.xmlhttp.re sponseXML and then assigning that.xmlhttp.re sponseText 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.javas cript. 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.goo glegroups.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.javas cript. 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.javas cript 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
5162
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 the function in the <head>; <script type="text/javascript"> function go() {
46
7029
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 other browsers) it stays on the same place (does not "open'' where the mouse is). And the links do not work when you click on them. If anyone has sugestions on how to improve it, please let me know.
18
5063
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
7785
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, nor opening a second box for display of the progress bar. I had been using the MegaUpload that was adapted from Raditha's script at http://www.raditha.com/upload.php . The MegaUpload script I have been using takes the progress bar inpage,...
33
8885
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 write type generic functions macros? #define CUBE(I) ( (I) * (I) * (I) ) Is there some more concise set of things where inline functions should be used instead of macros? Multi-statement macros, for example?
0
1016
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 dropdown, the position of the subsequent DropDownExtender's DropDownControl changes from the bottom right to the Middle left. (The DropDownControl appears directly left of the TargetControl, rather than beneath the TargetControl.) How do I ensure the...
3
1535
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 script into that page asynchronously using AJAX I can also run everything well for another user using the same client I load all the same things; the external, internal and inline javascript of the original page (so not the AJAX part) works perfect....
17
8371
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 the function if possible" (because if the compiler has the function definition available at an instantiation point, it will estimate whether to inline it or not, and do so if it estimates it would be beneficial, completely regardless of whether...
0
8633
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
9199
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7787
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
6552
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
5891
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();...
0
4392
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3076
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
2
2366
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.