473,386 Members | 1,752 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,386 software developers and data experts.

Two ajax functions on one page? mine are fighting!

26
Hi guys,

Let me just introduce my problem - i hope someone will be able to help! I have an index page for my site where i want the user to have the choice to view a login form or registration form. I have index.php with two links ("Click to login", "Click to Register"). I want to use ajax so that the user can switch between the forms without having to load the page. At the moment i have the forms stored in seperate html pages and i want the revelvant page to fill itself into a div called "content", depending on what the user would like to see. Here is my code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript" language="javascript">
  4. function registerRequest() {
  5.     var httpRequest;
  6.     var url="registration_form.php"
  7.  
  8.     if (window.XMLHttpRequest) { // Mozilla, Safari, ...
  9.         httpRequest = new XMLHttpRequest();
  10.         if (httpRequest.overrideMimeType) {
  11.             httpRequest.overrideMimeType('text/xml');
  12.             // See note below about this line
  13.         }
  14.     } else if (window.ActiveXObject) { // IE
  15.         try {
  16.             httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
  17.         } catch (e) {
  18.             try {
  19.                 httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
  20.             } catch (e) {
  21.             }
  22.         }
  23.     }
  24.  
  25.     if (!httpRequest) {
  26.         alert('Your browser does not support the features needed for this website');
  27.         return false;
  28.     }
  29.     httpRequest.onreadystatechange = function() {
  30.         if (httpRequest.readyState == 4) {
  31.             if (httpRequest.status == 200) {
  32.                 document.getElementById('content').innerHTML = httpRequest.responseText;
  33.             } else {
  34.                 alert('There was a problem with the site.');
  35.             }
  36.         }
  37.     };
  38.     httpRequest.open('GET', url, true);
  39.     httpRequest.send('');
  40.     httpRequest.close;
  41. }
  42. function loginRequest() {
  43.     var httpRequest2;
  44.     var url2="login_form.php"
  45.  
  46.     if (window.XMLHttpRequest) { // Mozilla, Safari, ...
  47.         httpRequest2 = new XMLHttpRequest();
  48.         if (httpRequest2.overrideMimeType) {
  49.             httpRequest2.overrideMimeType('text/xml');
  50.             // See note below about this line
  51.         }
  52.     } else if (window.ActiveXObject) { // IE
  53.         try {
  54.             httpRequest2 = new ActiveXObject("Msxml2.XMLHTTP");
  55.         } catch (e) {
  56.             try {
  57.                 httpRequest2 = new ActiveXObject("Microsoft.XMLHTTP");
  58.             } catch (e) {
  59.             }
  60.         }
  61.     }
  62.  
  63.     if (!httpRequest2) {
  64.         alert('Your browser does not support the features needed for this website');
  65.         return false;
  66.     }
  67.     httpRequest2.onreadystatechange = function() {
  68.         if (httpRequest2.readyState == 4) {
  69.             if (httpRequest2.status == 200) {
  70.                 document.getElementById('content').innerHTML = httpRequest2.responseText;
  71.             } else {
  72.                 alert('There was a problem with the site.');
  73.             }
  74.         }
  75.     };
  76.     httpRequest2.open('GET', url2, true);
  77.     httpRequest2.send('');
  78. }
  79. </script>
  80. </head>
  81. <link rel="stylesheet" type"text/css" href="css/style.css" />
  82. <body>
  83. <div id="choice">
  84. <table>
  85.     <tr>
  86.         <td><u><a onMouseUp="loginRequest()">Click to Login</a></u>
  87.         </td>
  88.     </tr>
  89.     <tr>
  90.         <td><u><a onMouseUp="registerRequest()">Click to Register</a></u>
  91.         </td>
  92.     </tr>
  93. </table>
  94. </div>
  95. <div id="cell">
  96. <div id="content">
  97. <?php include "login_form.php"; ?>
  98. </div>
  99. </div>
  100. </body>
In firefox only the registration link is working (or so it seems). In IE it is the same, although it tells me that there is an object expected on line 48 ("httpRequest2.overrideMimeType('text/xml')"). Is it ok to have two ajax function s on the same page, after all they shouldnt be both being used at the same time?

Thanks for your time guys.

Chris
Jan 14 '08 #1
3 1594
rpnew
188 100+
hi,
There is nothing wrong with using two function on the same page.
I've used more than that with my project so i dont think its a problem. Your problem is somewhere else as i think......

Regards,
RP
Jan 14 '08 #2
cbellew
26
Thanks, i thought as much, i will keep trying to figure it out myself.
Jan 14 '08 #3
acoder
16,027 Expert Mod 8TB
Why are you 'closing' the request on line 40?
Jan 14 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: GTi | last post by:
I have a ASP 2.0 page where I use some Ajax code. The Ajax code (JavaScript) is inserted from CodeBehind. In my page I have a submit button and some links for Ajax functions. When I load the page...
4
by: Frances | last post by:
I literally started learning AJAX just last weekend.. I have this page, http://www.francesdelrio.com/ajax/db2.html, where I'm essentially doing what's here,...
4
by: Seguros Catatumbo | last post by:
Hi guys, i am having some weird issue with an ajax page. I am designing a simple ajax calendar, because the one over yahoo is about 200kb long, and mine is 9kb and really simple. I am using...
5
by: Martin | last post by:
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...
3
by: Sandman | last post by:
So, I've used ajax for quite some time for different stuff. Mostly I just feed a funktion I made with the ID of the DIV that should be updated with the output from page XXX.php Now I want to...
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
10
by: =?Utf-8?B?RGFuaQ==?= | last post by:
Hi, Trying to create a master page that holds a menu, and the menu switches between pages in the site. 2 problem arrosed: a. When I navigate from page to page (all AJAX Web Forms, with the...
1
by: John Straumann | last post by:
Hello all: I am a CRM Solution Architect so not a .NET expert by any means. I am working with a customer who needs to modify the Advanced find in CRM which works as shown here: ...
8
by: knkk | last post by:
Instead of an id getting its innerHTML changed, the entire page is getting refreshed with this function of mine (you may want to look just at the end of the function where there's an alert): ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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.