On Jun 5, 9:36 pm, sheldonlg <sheldonlgwrote :
Dan Rumney wrote:
sheldonlg wrote:
I am looking for a clean solution to a problem that I solved in, what
I call, a "dirty" way.
[snip]
Could you provide your dirty code, please?
Sure (in a mixture of code and pseudocode):
*************** *
Javascript processing:
(...the important two lines in handling the response...)
var resp = postProcess(pOb jRequest.respon seText);
document.getEle mentById('foo') .innerHTML = resp;
function postProcess(txt ) {
var hideIt = txt.substring(0 ,1);
var editButton = document.getEle mentById('showE dit');
if (hideIt == 0)
editButton.styl e.display = 'none';
else
editButton.styl e.display = '';
return txt.substring(1 );
}
You can of course use closure to pass the required parameter:
var hideIt; // the variable you wish to pass
ajax.onreadysta techange = function () {
if (ajax.readyStat e == 4) {
if (hideIt) {// here you can use the variable..}
}
}
If you want to pass the value rather than the variable itself:
var hideIt;
(function (myHideIt) {
ajax.onreadysta techange = function () {
if (ajax.readyStat e == 4) {
if (myHideIt) {// check the passed value..}
}
}
})(hideIt) // pass the value of hideIt
Or if you prefer, you can wrap this up in a function that generates a
function:
function makeAjaxCallbac k (ajaxObject,myH ideIt) {
return function () {
if (ajaxObject.rea dyState == 4) {
if (myHideIt) {// check the passed value..}
}
}
}
ajax.onreadysta techange = makeAjaxCallbac k(ajax,hideIt);
There are many ways to use closure to do this depending on exactly
what you want and, to some degree, preferred style. 4 1978
slebetman wrote:
On Jun 5, 9:36 pm, sheldonlg <sheldonlgwrote :
>Dan Rumney wrote:
>>sheldonlg wrote: I am looking for a clean solution to a problem that I solved in, what I call, a "dirty" way. [snip] Could you provide your dirty code, please?
Sure (in a mixture of code and pseudocode):
************** **
Javascript processing: (...the important two lines in handling the response...) var resp = postProcess(pOb jRequest.respon seText); document.getEl ementById('foo' ).innerHTML = resp;
function postProcess(txt ) { var hideIt = txt.substring(0 ,1); var editButton = document.getEle mentById('showE dit'); if (hideIt == 0) editButton.styl e.display = 'none'; else editButton.styl e.display = ''; return txt.substring(1 );
}
You can of course use closure to pass the required parameter:
var hideIt; // the variable you wish to pass
ajax.onreadysta techange = function () {
if (ajax.readyStat e == 4) {
if (hideIt) {// here you can use the variable..}
}
}
If you want to pass the value rather than the variable itself:
var hideIt;
(function (myHideIt) {
ajax.onreadysta techange = function () {
if (ajax.readyStat e == 4) {
if (myHideIt) {// check the passed value..}
}
}
})(hideIt) // pass the value of hideIt
Or if you prefer, you can wrap this up in a function that generates a
function:
function makeAjaxCallbac k (ajaxObject,myH ideIt) {
return function () {
if (ajaxObject.rea dyState == 4) {
if (myHideIt) {// check the passed value..}
}
}
}
ajax.onreadysta techange = makeAjaxCallbac k(ajax,hideIt);
There are many ways to use closure to do this depending on exactly
what you want and, to some degree, preferred style.
I don't understand. How is the hideIt variable set (in the php
script)?. How does the javascript know that there is a variable hideIt
that is coming back? My line:
var resp = postProcess(pOb jRequest.respon seText);
is already inside an
if (ajaxObject.rea dyState == 4) {}
block that returns the string for the innerHTML.
On Jun 6, 7:47*am, sheldonlg <sheldonlgwrote :
slebetman wrote:
I don't understand. *How is the hideIt variable set (in the php
script)?. *How does the javascript know that there is a variable hideIt
that is coming back? *My line:
var resp = postProcess(pOb jRequest.respon seText);
is already inside an
if (ajaxObject.rea dyState == 4) {}
block that returns the string for the innerHTML.
Okay. Asynchronous Javascript XML = AJAX. HTML is not a transport
protocol and generating HTML on the server through PHP responses sort
of contradicts the purpose of AJAX. Rethink your design. Use
Javascript to generate markup from data, use XML or JSON for
transporting that data. If you do this, some of the other poster's
solutions will begin to make sense.
I know there are tons of examples on the net of AJAH but, in my humble
opinion, that's why they're called script kiddies.
Bob
beegee wrote:
On Jun 6, 7:47 am, sheldonlg <sheldonlgwrote :
>slebetman wrote:
>I don't understand. How is the hideIt variable set (in the php script)?. How does the javascript know that there is a variable hideIt that is coming back? My line:
var resp = postProcess(pOb jRequest.respon seText);
is already inside an
if (ajaxObject.rea dyState == 4) {}
block that returns the string for the innerHTML.
Okay. Asynchronous Javascript XML = AJAX. HTML is not a transport
protocol and generating HTML on the server through PHP responses sort
of contradicts the purpose of AJAX. Rethink your design. Use
Javascript to generate markup from data, use XML or JSON for
transporting that data. If you do this, some of the other poster's
solutions will begin to make sense.
I know there are tons of examples on the net of AJAH but, in my humble
opinion, that's why they're called script kiddies.
Bob
I **think** I understand what you are saying.
This application happens to be for recipes, and the dropdown list is a
list of recipes. That dropdown list is not created through AJAX. Now,
when the user clicks on a particular recipe, I send an AJAX call. On
the server it looks up the data for the recipe from the database. What
I then do now is to generate the entire html portion of the recipe to
fit into a div on the bottom of the page (via innerHTML).
I guess what you are saying is to send back an xml string containing the
data and use javacript on the browser to process that xml string,
placing all the data into the appropriate tags on the bottom of the page
(since the bottom of the page always has the same fields). In that
case, including another field in the XML would, indeed, be trivial.
Am I reading you correctly?
On Jun 6, 10:21 am, sheldonlg <sheldonlgwrote :
beegee wrote:
On Jun 6, 7:47 am, sheldonlg <sheldonlgwrote :
slebetman wrote:
I don't understand. How is the hideIt variable set (in the php
script)?. How does the javascript know that there is a variable hideIt
that is coming back? My line:
var resp = postProcess(pOb jRequest.respon seText);
is already inside an
if (ajaxObject.rea dyState == 4) {}
block that returns the string for the innerHTML.
Okay. Asynchronous Javascript XML = AJAX. HTML is not a transport
protocol and generating HTML on the server through PHP responses sort
of contradicts the purpose of AJAX. Rethink your design. Use
Javascript to generate markup from data, use XML or JSON for
transporting that data. If you do this, some of the other poster's
solutions will begin to make sense.
I know there are tons of examples on the net of AJAH but, in my humble
opinion, that's why they're called script kiddies.
Bob
I **think** I understand what you are saying.
This application happens to be for recipes, and the dropdown list is a
list of recipes. That dropdown list is not created through AJAX. Now,
when the user clicks on a particular recipe, I send an AJAX call. On
the server it looks up the data for the recipe from the database. What
I then do now is to generate the entire html portion of the recipe to
fit into a div on the bottom of the page (via innerHTML).
I guess what you are saying is to send back an xml string containing the
data and use javacript on the browser to process that xml string,
placing all the data into the appropriate tags on the bottom of the page
(since the bottom of the page always has the same fields). In that
case, including another field in the XML would, indeed, be trivial.
Am I reading you correctly?
Yup. You have it. In this way you're emulating the classic client-
server application and keeping UI and data separate. If you don't
care about security too much, JSON is a even better bet than XML cause
there is no parsing involved on the Javascript side. You just eval
the result and you've got a javascript object.
Bob This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: G Matthew J |
last post by:
interesting "signal vs. noise" blog entry:
http://37signals.com/svn/archives2/whats_wrong_with_ajax.php
|
by: javainfo |
last post by:
How can i refresh IFRAME and load data through AJAX?
|
by: darrel |
last post by:
Last week I asked about ASP.net 2.0 AJAX frameworks and there appears to be
several to choose from.
I haven't used ASP.net 2.0 yet, but from doing a bit of reading, it appears
that ASP.net 2.0 also has some client side call-backs built in that can
update the display via AJAX.
To ask a more specific question, do I need a specific AJAX framework to do
the following:
|
by: Tony |
last post by:
I just noticed that prototype.js is one of the files in the Ajax.NET
distribution - I'm pretty concerned about this. Does anyone know if this
is the same "prototype.js" that is not well-liked around here?
If so, do you know if Ajax.NET can be used without prototype.js?
--
"The most convoluted explanation that fits all of the made-up facts is
the most likely to be believed by conspiracy theorists. Fitting the
|
by: codefragment |
last post by:
Hi
I have asked this on the official asp.net forums but no luck so
thought I'd try here
Assume you have a page with a filter control and a grid view and many
other controls on it. When the filter changes you want the gridview to
change but nothing else. In particular all you would like to happen is
for an ajax call to occur and a new grid view to be returned.
| |
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= |
last post by:
I'm about to finally make the jump and start a new site using AJAX. THe
question i have for all of you AJAX developers out there is which one?
1. The Standard AJAX frame work
2. The Tool kit.
3. Or are there others out there.
4. Should i not do AJAX at all because it still posts back the entire page
even though
only the section is refreshed. (someone tell me i'm wrong here and why
please!)
|
by: =?Utf-8?B?VG9u?= |
last post by:
Hello,
I want to understand teh benefits of ajax technology. Does anyone has a good
website where AJAX EXTENSIONS is worked out so I really understand it.
There a 2 main questions:
1) How about the form load event. Why should it fire when I put a button in
a update panel? Is this necessary and is only the other controls related to
the update panel send back? Or the whole page (If this is true I really do
not get it). But please answer...
|
by: Cirene |
last post by:
3 quick questions...
1. Are the controls in the AJAX Futures download "beta" or the release and
stable version?
2. Also, where is the best way to learn how to implement these? (Other than
by downloading the stuff at asp.net/ajax.)
3. When will the new version of AJAX be out? Will it be included with the
Visual Studio 2008 release?
|
by: Jonathan Wood |
last post by:
Greetings,
I'd like to implement some AJAX features on an existing ASP.NET site. I have
one example of doing this but, otherwise, don't know much about it.
I have one question, though, about getting started: I notice that there are
project templates for creating AJAX this and AJAX that. I'm a little
confused about this. Am I not able to add AJAX features to an existing Web
form? Why is it necessary to select an AJAX form or whatever?
|
by: sheldonlg |
last post by:
I am looking for a clean solution to a problem that I solved in, what I
call, a "dirty" way.
Here is what I want to do. I have a dropdown list. Clicking on an item
in the dropdown list invokes an AJAX call that gets data which populates
the entire lower part of my screen. It does this with an innerHTML for
the div tag that holds all of this. This works fine.
I also have an "Edit" button that I want to show next to dropdown list,...
|
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...
| |
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...
|
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,...
|
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
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...
|
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();...
| |
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
|
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...
| |