473,573 Members | 5,087 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Complete page using AJAX, how?!?

Hello NG,

I've been doing some AJAX for a few weeks now. The basics worked fine so
far, but now I've got the following problem which I can't solve:

With AJAX you typically update/replace only parts of your page. But in
my application there are situation when I first notice on the server --
so AFTER sending an AJAX request -- that I have to update the complete
page instead of only some parts. And what do I do now???
- Possibility 1: (That's how I do it at the moment)
I send the complete html source code to the client and do the following:

document.open() ;
document.write( complete_html_c ode);
document.close( );

Basically it works, however, my page is destroyed when I press F5
afterwards. It seems like the included CSS and JS in the header are not
"loaded" correctly - even though everything looks and functions
correctly before pressing F5. Any ideas???
- Possibility 2:
For a complete update I only send the URL for the according page to the
client. On the client I extract the this URL from the received XML and
do the following: document.locati on.href = extractedUrl;

Even though this should work, this solution always requires two requests
- the AJAX-request and the later JS-redirect. Thats not good either...
-Possibility 3:
I'm sure that I'm not the first person having this problem. Are the any
other solutions or maybe even some kind of patters to solve my problem?
Thanks in advance,

Martin
Sep 18 '06 #1
5 2203
Of course the subject should be: "Complete page UPDATE using AJAX"
Sorry,

Martin
Sep 18 '06 #2
Martin wrote:
Hello NG,

I've been doing some AJAX for a few weeks now. The basics worked fine so
far, but now I've got the following problem which I can't solve:

With AJAX you typically update/replace only parts of your page. But in
my application there are situation when I first notice on the server --
so AFTER sending an AJAX request -- that I have to update the complete
page instead of only some parts. And what do I do now???
- Possibility 1: (That's how I do it at the moment)
I send the complete html source code to the client and do the following:

document.open() ;
document.write( complete_html_c ode);
document.close( );

Basically it works, however, my page is destroyed when I press F5
afterwards. It seems like the included CSS and JS in the header are not
"loaded" correctly - even though everything looks and functions
correctly before pressing F5. Any ideas???
- Possibility 2:
For a complete update I only send the URL for the according page to the
client. On the client I extract the this URL from the received XML and
do the following: document.locati on.href = extractedUrl;

Even though this should work, this solution always requires two requests
- the AJAX-request and the later JS-redirect. Thats not good either...
-Possibility 3:
I'm sure that I'm not the first person having this problem. Are the any
other solutions or maybe even some kind of patters to solve my problem?
Thanks in advance,

Martin
A better question would be: "Complete page using AJAX, why?!?"

Ask yourself if AJAX is improving the user experience, or simply
complicating development. Is this the purpose for which the technology
was designed?

Remember the KISS principle: "Keep it simple, stupid!" AJAX is icing on
the cake; it's rare that it can be justified for an application's
usefulness to hinge upon it.

Jeremy
Sep 18 '06 #3

Jeremy wrote:
Martin wrote:
Hello NG,

I've been doing some AJAX for a few weeks now. The basics worked fine so
far, but now I've got the following problem which I can't solve:

With AJAX you typically update/replace only parts of your page. But in
my application there are situation when I first notice on the server --
so AFTER sending an AJAX request -- that I have to update the complete
page instead of only some parts. And what do I do now???
I'm going to assume that you're using Ajax for server side validation
of form data and should all data be correct, then you want to go ahead
and submit the action?


- Possibility 1: (That's how I do it at the moment)
I send the complete html source code to the client and do the following:

document.open() ;
document.write( complete_html_c ode);
document.close( );

Basically it works, however, my page is destroyed when I press F5
afterwards. It seems like the included CSS and JS in the header are not
"loaded" correctly - even though everything looks and functions
correctly before pressing F5. Any ideas???
This is generally speaking a bad idea. You should abandon this practice
immediately.


- Possibility 2:
For a complete update I only send the URL for the according page to the
client. On the client I extract the this URL from the received XML and
do the following: document.locati on.href = extractedUrl;
This is not that big a deal and is not a bad way to go.

Even though this should work, this solution always requires two requests
- the AJAX-request and the later JS-redirect. Thats not good either...
-Possibility 3:
I'm sure that I'm not the first person having this problem. Are the any
other solutions or maybe even some kind of patters to solve my problem?
Consider something like the following:

<form action="myserve rside.php" onsubmit="retur n checkIt();">
....
</form>

Notice that the form has an action defined which would be the url to
your "next" page. It also has an onsubmit that returns the result of a
checkIt(0 function.

This checkIt() function would do your Ajax request and get the results
from your server. It would then return true should validation pass, or
if validation fails you would perform your page updates and then return
false.

This will still result in the 2 requests you mention in Option 2, but
somehow seems to be a more elegant solution. Why? I dunno...I also
prefer Miracle Whip over mayonnaise.


Thanks in advance,

Martin

A better question would be: "Complete page using AJAX, why?!?"

Ask yourself if AJAX is improving the user experience, or simply
complicating development. Is this the purpose for which the technology
was designed?

Remember the KISS principle: "Keep it simple, stupid!" AJAX is icing on
the cake; it's rare that it can be justified for an application's
usefulness to hinge upon it.

Jeremy
Sep 19 '06 #4
A better question would be: "Complete page using AJAX, why?!?"
I don't have the option to use AJAX or not. My boss and our client wants
it, so the question is definitely "how", not "why".
Regards,
Stephan
Sep 19 '06 #5
I'm going to assume that you're using Ajax for server side validation
of form data and should all data be correct, then you want to go ahead
and submit the action?
No, it's completely different but too complex to explain. So just take
it as a fact that in my application there are definitly some cases where
i have to do a full update after sending an AJAX request.
This is generally speaking a bad idea. You should abandon this practice
immediately.
Hmmm, and why?
This is not that big a deal and is not a bad way to go.
But won't this lead to problems when I later on try to support the back
button?
Consider something like the following:

<form action="myserve rside.php" onsubmit="retur n checkIt();">
...
</form>

This checkIt() function would do your Ajax request and get the results
from your server. It would then return true should validation pass, or
if validation fails you would perform your page updates and then return
false.
As I said, the problem is a bit more complex. It's an existing
application in which I have to integrate AJAX and the current design
forces me to do a full update in certain situations. But is has nothing
to do with form validation.
Regards,
Martin
Sep 19 '06 #6

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

Similar topics

2
2733
by: 1kHz | last post by:
Hi all.. I'm new with this Ajax thingy and have done some experimenting. I did some codes according to examples from http://www.webpasties.com/xmlHttpRequest/ and http://www.jamesdam.com/ajax_login/login.html In my code, I request a PHP page that will iterate 10000 times and return a 10000 line of text, and then put it in a DIV. I...
4
3255
by: Jono | last post by:
Hi Everyone, As it says in the title, I'm looking for a way to display a page while long running operations are performed on the server. Ideally, I'd like some way to push the current request onto some stack, where it would continue to be processed asynchronously (most importantly preserving things like view state, form post data, etc). In...
1
5183
by: rocksoft | last post by:
Hi, i have devloping web application in Asp.net and c#, i have used ajax to achieve the auto complete text box, my company using visual studio 2003, ajax auto complete text box working fine with ms sql database, but it throughing some script error and not working, anybody to help me to solve this problem, how to make the ajax...
14
23133
by: lmttag | last post by:
Hello. We're developing an ASP.NET 2.0 (C#) application and we're trying to AJAX-enable it. We're having problem with a page not showing the page while a long-running process is executing. So, we're looking for a way to display the page with a "please wait..." message while the process is running, and then, when the process is done, update...
1
1966
by: empiresolutions | last post by:
im using the script.aculo.us drag n drop script. i am having an issue getting a checkbox to POST its value if checked, once the row the checkbox is in is moved. I believe that once i change the position of a checkbox, it is no longer considered a child of the parent form. How can i get it back to being part of the original parent form? Another...
10
3447
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
2715
hsriat
by: hsriat | last post by:
I have a page working on Ajax. The problem is, after doing many changes using Ajax (like uploading, changing name, adding to favorites etc), the status bar starts behaving unexpectedly. Even when nothing is being transfered, it displays Transferring data from localhost... and that too continuously. The progress bar also shows that its working, and...
2
6497
dlite922
by: dlite922 | last post by:
Hey guys been a while since I needed your help. I've got a reporting system (yes same old one) , one button runs the report and builds the html table into the page all nice with CSS, etc, the other button produces a CSV output. I set the header variables (content-type, etc...) so that the user gets the Open/Save/Cancel prompt instead of...
7
7830
by: Microsoft Newsserver | last post by:
Hi Folks. I have an issue I need some help with if thats OK. I am running Framework 2.0 using Windows Integrated Security. For most of the application we manage session timeouts without the user knowing anything about it by ensuring all the essential objects ( only a few ) are in place during session start. For performance, there are...
0
7709
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...
0
8039
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
8218
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
7800
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
8091
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
5605
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
3744
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1049
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...

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.