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

How to capture a whole page through Ajax

I have a list box in a site with which I capture a selected value with the onChange event using the capture_value() function (code listed below).
This function passes 2 arguments, i.e., 'str' which is the selected list box value and 'passed_url' which is a passed url for running a php script (which contains some url query parameters, e.g. 'somescript.php?var1=value1&var2=value2&var3=value3').

The capture_value() function actually sends a Ajax request with the GET method and a URL which is formed by appending the captured list box value to the 'passed_url' url value (i.e. the 'passed_url' is changed to 'somescript.php?var1=value1&var2=value2&var3=value 3&str=value4'.
Now, what I want to do is to capture the whole generated page from running the final 'passed_url' in the same window (as if I entered 'somescript.php?var1=value1&var2=value2&var3=value3 &str=value4' in the location
field of the browser and pressed <Enter>).

In other words, I want to output in the same window the generated page from running the 'somescript.php?var1=value1&var2=value2&var3=value3 &str=value4' url address.

Below is the code listing of the Javascript file I use.
----------------------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. var xmlhttp;
  2.  
  3. function capture_value(passed_url,str)
  4. {
  5. xmlhttp=GetXmlHttpObject();
  6. if (xmlhttp==null)
  7.   {
  8.   alert ("Browser does not support HTTP Request ");
  9.   return;
  10.   }
  11. //var url="http://www.test.local/ach_handcrfts/product.php";
  12. passed_url=passed_url+"&drawing_style="+str;
  13. passed_url=passed_url+"&sid="+Math.random();
  14. //alert ("url: " + url);
  15. xmlhttp.onreadystatechange=stateChanged;
  16. xmlhttp.open("GET",passed_url,true);
  17. xmlhttp.send(null);
  18.  
  19. }
  20.  
  21. function stateChanged()
  22. {
  23. if (xmlhttp.readyState == 4) {
  24.         if (xmlhttp.status == 200) {
  25.            window.open(xmlhttp.responseXML,"_self");
  26.  
  27.         } else {
  28.             alert("Response Error:n" + xmlhttp.statusText);
  29.         }
  30.     }
  31.  
  32. }
  33.  
  34. function GetXmlHttpObject()
  35. {
  36. if (window.XMLHttpRequest)
  37.   {
  38.   // code for IE7+, Firefox, Chrome, Opera, Safari  
  39.   return new XMLHttpRequest();
  40.   }
  41. if (window.ActiveXObject)
  42.   {
  43.   // code for IE6, IE5
  44.   return new ActiveXObject("Microsoft.XMLHTTP");
  45.   }
  46. return null;
  47. }
Now, when I select a value in the list box, the desired page is not generated (nothing happens). When I check
with Firebug, I can see that I have no errors, and
I get the expected GET response in the Firebug console, and when I click on it's console link with the right
button and then click on "Open in New Tab", a new browser window opens with the expected page, but this page is not generated by selecting a value in the list box, i.e. somewhere in the end of the code I need to add some code to output the whole page in the same window.

I am sure it's something simple missing or needing modification.
Could you please somebody help?
Jun 26 '09 #1
5 3147
acoder
16,027 Expert Mod 8TB
Why are you using window.open()? Try something like:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("container").innerHTML = xmlhttp.responseText;
where "container" is the containing element, e.g.
Expand|Select|Wrap|Line Numbers
  1. <div id="container"></div>
Jun 26 '09 #2
ok, I had a clue that I was not using window.open method correctly. Now, I want the container to be the browser window itself (the same one). In other words I want to output the page generated from the 'passed_url' script in the same browser window and not in a page element.
Could you please specify the code for this?
Jun 26 '09 #3
acoder
16,027 Expert Mod 8TB
If that's the case, then there's no need for Ajax. Just link to the page, e.g. via a form submit, or by changing the location.href property.
Jun 26 '09 #4
ok acoder, thanks for the help.
I just erased everything having to do with Ajax and added the line:
Expand|Select|Wrap|Line Numbers
  1. window.location.href=passed_url;
and left the rest of the code intact.
So the job is done by refreshing the page.

What though, if I didn't want to have a page refresh and I wanted to capture into the <body> element the part from the xmlhttp.responseText or the xmlhttp.responseXML that is contained in the <body> element in the server response?

The thing is that 'passed_url' generates a page with not only updated values in the list box but also with some generated Javascript code (array values, etc) which I would want to capture with Ajax. So if I captured the whole <body> element content and left the rest intact (<head>, etc) I would get all the generated source for the updated page.
I am not sure if I am correct in my logic....
Jun 26 '09 #5
acoder
16,027 Expert Mod 8TB
If I'm following this correctly, what would be best for you is to make an Ajax request to a simple PHP page which simply returns the part that needs changing and change that in the page. If the change doesn't require PHP, then use JavaScript, e.g. if you could store the info. in an array.

To better understand this, post the rest of the relevant code.
Jun 28 '09 #6

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

Similar topics

4
by: jxiang | last post by:
I created a child form that is much bigger than the MDI form in VB.Net. I am trying to capture the whole child form and save as an image or sent to printer. I tried to use BitBlt to capture the...
15
by: Jake Barnes | last post by:
I'm trying to learn AJAX so tonight I sat down and came up with a little toy that I can do tests with. You can see it here: http://www.publicdomainsoftware.org/ajaxExperiment.htm I've got...
4
by: evgenyg | last post by:
Hello ! We have the following situation - when Ajax request is sent what's being returned by the server is usually an XML (which is used for DOM updates) but sometimes it's HTML which is a whole...
3
by: DanWeaver | last post by:
New to asp. using VS2005. I have an HTML page with various elements and moveable graphics- when I make an asp action (selecting some rows from a sql dbase) the whole page is refreshed and I lose...
0
by: chrisexv6 | last post by:
Here's an interesting issue: if I open a .SLN file thru Visual Studio, "Build Web Site" and run it, the AJAX stuff refreshes the whole page. However, if I go into VS and do File, Open Web Site,...
1
by: empiresolutions | last post by:
i want to do a screen capture/scrape of a page, resulting in a JPG or PNG that i could save in a dir of my choice. This capture needs to take place a few seconds after the page loads, to allow all...
7
by: Lit | last post by:
Hi, How can I capture the vertical scroll bar position for a Listbox. I have a Listbox of 100 items + when I click on it I post back remove the item selected. After returning to the client...
1
by: farghal | last post by:
Hello as many people I'm new to ajax but trying my best to understand. At this point I got a problem I'm not able to solve. I've looked on several forums and googled internet but I can't find a...
0
by: arjosoer | last post by:
I'm writing a small utility to capture all requests made to a web server from a windows application using the axWebBrowser control. So far I have the following working, as the user traverse the...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...
0
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.