Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

AJAX Please wait while your page is loading, script problem

Posted on 2009-04-01
2
Medium Priority
?
1,250 Views
Last Modified: 2012-05-06
Hello,

I have a multi page form, page 4 loads to slow so I wanted to use a loader, ajax or otherwise, to notify the customer that their request is being processed.  Just need a simple way for now I plan on recoding the entire form soon.

Below is what I have, found on a forum, doesnt appear to work at all.

Any thoughts?

Thanks,
<script type="application/javascript">
	
	function getHTTPObject() {
	if (typeof XMLHttpRequest != 'undefined') {
	return new XMLHttpRequest();
	}
	try {
	return new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	try {
	return new ActiveXObject("Microsoft.XMLHTTP");
	} catch (e) {}
	}
	return false;
	}
	
	var http = getHTTPObject();
	
	function handleHttpResponse() {
	
	if (http.readyState == 4) {
	var temp = http.responseText;
	document.getElementById("PHPDATA").innerHTML=temp;
	}
	}
	
	
	function LoadData(){
	
	var url = "main.php?type=cp&page=4";
	http.open("GET", url, true);
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
	}
	</script>
    </head>
    <body onload="javascript:LoadData()">
   
   <div id="PHPDATA">
    <span class="teal_header" >
    	<h4>Please wait as we process your request</h4>
    </span>
	<p class="body" style="text-align:center;">
    	This should only take a moment.
    </p>
   </div>

Open in new window

0
Comment
Question by:vrmetro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
FirestormX earned 2000 total points
ID: 24043367
It depends on what is slowing down the last page of the form. If it is slow because it is doing some heavy processing (such as editing a large image or something), then there isn't a whole lot you can do to show that the page is loading.

It MIGHT be possible to create a "loading" image (or soemthing) and make it display that in the HTML, then right after it is displayed, you do your heavy processing functions, then in your <body> tag, you make an "onload" change the image back. Like so:

<html>
<head></head>
<body onload="document.getElementById('loading').style.display='none';">
<img src="loading.gif" alt="" id="loading" />
<?php
//heavy stuff
?>
</body>
</html>

I have no idea if this will work, and I would think it would depend on the browser (if it will display part of the data if it hasn't recieved all of it), but in general, I would say that what you are asking isn't possible if you are loading a page.
IF you were taking the data from the form and dynamically processing it in ajax, THEN you could do something like
<form onsubmit="submit_form(this)">
Then in the submit_form() javascript function, you can make a loading image appear, then do your processing, then when the readyState of the ajax gets to 4 (finishes) you can change the loading image to a success image.
0
 

Author Comment

by:vrmetro
ID: 24043659
@FirestormX

Good info, thank you.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question