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

Page reload inside a DIV not working with Ajax. How do I solve it ?

Hello,

I have had the following problem with Ajax for a few days, and have not been able to solve it even after a few suggestions :

- The two files I mention here are copied at the end of this mail, so anyone can look if necessary.

I have a main document called : main.php
and a sub-document called : SubOne.php

My intention is to :
1) Bring the contents of SubOne.php into the area defined by the DIV tag named "MyDiv" when I press the button (in main.php).
2) Use the "Form Button" inside SubOne.php to change the text from :
"This is the subwindow one. We did not get any message"
to :
"This is the subwindow one. We got a message"

The first part works OK, but the second part does not work the way I want.
When I push the "Form Button" the text changes, but it reloads using the whole window. I want the text to change while staying in the MyDiv area and leaving alone the top part of my main.php window.

Can someone tell me what I need to change to make it work.

Thanks in advance for any tip or suggestion.

Michel


---------------------- Here is the code ----------------------


================== Beginning of main.php ==================
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Main Window</title>
  4. <script type="text/javascript">
  5. function loadXMLDoc()
  6. {
  7. if (window.XMLHttpRequest)
  8. {// code for IE7+, Firefox, Chrome, Opera, Safari
  9. xmlhttp=new XMLHttpRequest();
  10. }
  11. else
  12. {// code for IE6, IE5
  13. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  14. }
  15. xmlhttp.onreadystatechange=function()
  16. {
  17. if (xmlhttp.readyState==4 && xmlhttp.status==200)
  18. {
  19. document.getElementById("MyDiv").innerHTML=xmlhttp.responseText;
  20. }
  21. }
  22. xmlhttp.open("GET","SubOne.php",true);
  23. xmlhttp.send();
  24. }
  25. </script>
  26. </head>
  27.  
  28. <body>
  29. This the main window.
  30. <Input Type="SUBMIT" Value="Load SubOne into MyDiv" onClick="loadXMLDoc()">
  31.  
  32. <br>----------------------------------------------------------------<br>
  33. <div ID='MyDiv'>
  34. This the MyDiv space.
  35. </div>
  36. <br>----------------------------------------------------------------<br>
  37.  
  38. </body>
  39. </html>
  40.  
================== End of main.php ==================


================== Beginning of SubOne.php ==================
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Subwindow One</title>
  4. </head>
  5.  
  6. <body>
  7. This is the subwindow one.
  8.  
  9. <?php
  10. $MSG=$_POST['MSG'];
  11. if ($MSG) echo "We got a message";
  12. else echo "We did not get any message";
  13. ?>
  14.  
  15. <BR><BR>
  16.  
  17. <FORM METHOD='POST' ACTION='SubOne.php'>
  18. <INPUT TYPE='SUBMIT' NAME='MSG' VALUE='Form Button'>
  19. </FORM>
  20.  
  21. </body>
  22. </html>
  23.  
================== End of SubOne.php ==================
Jun 24 '10 #1
1 1777
johny10151981
1,059 1GB
you better try iframe instead div.
for debug purpose try to see on alert what you see.
Jun 24 '10 #2

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

Similar topics

8
by: Dynamo | last post by:
Yep its me again, I have succesfully created a login page for my site. I have used the PHP_SELF so that once the user has succesfully logged on the page reloads. Everything works fine the first...
8
by: DKM | last post by:
Here are the source code files to a Java applet that utilizes LiveConnect to communicate with Javascript, and the HTML file. The thing works both in IE 6.0 and FireFox 1.4. but with some...
3
by: michael | last post by:
Good Morning Everyone, I am writing a script to add and remove rows from a table. Here are the two functions: function newRow(rowNo) { var theTable = document.getElementById("table1");...
2
by: Brenden Bixler | last post by:
Hello. I've got a long web form that has to reload 6-7 times to validate data (sigh, I know) making for a rocky-enough experience for users. To add insult to injury, each time the page reloads,...
0
by: TMT32 | last post by:
Hi, This is my first time using treeview in asp.net, but there has a problem is how to keep treeview expand status after page reload with new parameter ? Becasue it only can choose expand level...
3
by: msinghal | last post by:
hi, I am facing one problem which is related to AJAX. I have a html page which has some links. When the page is refreshed using AJAX then if some new new link is added to the page on this refresh,...
1
by: David C | last post by:
Is it possible to have an aspx page reload every nn minutes? I assume I would have to do something in Javascript at the client? I want my ASP.Net application to display running dollars collected...
2
by: ramanaths | last post by:
Hi I have a page that shows many thumbnail images. on load of this page i have some code that invokes a javascript which shows a message saying 'loading images'... this is hidden once all the...
1
by: pendem | last post by:
I mean can set a variable value in a script to be unchanged even after page reload? for example if i set a value of a global variable "val" to 2 ; so using onbeforeunload() or onunload(), i will...
5
by: raamay | last post by:
i have a form via which new users can register their information along with their Resume. Now when input validation is done, if there is some errors, then the page is reloaded with the users...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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...

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.