473,836 Members | 1,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to capture a whole page through Ajax

3 New Member
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&var 2=value2&var3=v alue3').

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&va r2=value2&var3= value3&str=valu e4'.
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&var 2=value2&var3=v alue3&str=value 4' 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&var 2=value2&var3=v alue3&str=value 4' 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 3166
acoder
16,027 Recognized Expert Moderator MVP
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
vasilis
3 New Member
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 Recognized Expert Moderator MVP
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
vasilis
3 New Member
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.respons eText or the xmlhttp.respons eXML 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 Recognized Expert Moderator MVP
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
3373
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 child form but I can only capture the visible part of the child form whatever you scroll to any part of the form. I have read the article in site http://www.fengyuan.com/article/wmprint.html unforturely it is for C++ instead of VB.Net. I tried to...
15
2077
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 Stuart Langridge's book "DHTML Utopia: Modern Web Design using Javascript and DOM" which seems pretty good. It covers the basics. The next thing I'd like to do is add a Save button to this little page I came up with. I may use Sam Stephenson's...
4
7480
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 new page that should replace an existing one. I.e when we issue an Ajax request we don't know what will be returned and analyze the response to act accordingly. Now, the way to replace the current document with a new one used to be easy and...
3
1364
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 the changes I have made ie moving graphics around etc. Is there any way to prevent this?
0
1409
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, open the root of where the same exact web site resides, then Build and run it, the AJAX stuff refreshes only the portions it should. The only difference I see between the two ways of opening the site is that when using "Open Web Site", an...
1
2100
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 JavaScript and Flash elements on page to load. It would be great if i could also/just target a specific JS or Flash element to grab, instead of the whole page. There has to be some great PHP solutions for this. Thanks, Cesar
7
5635
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 browser the list box scroll position is at the top.
1
9045
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 solution :S. This is the basic idea: I'm trying to implement Ajax in a Portal page created in weblogic 9.2. I've created a portlet with the name Ajax.jsp and an additional page called test.jsp. Ajax.jsp is the main portlet page. And uses the...
0
998
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 website clicking on links, posting forms etc I capture the webpage and the data being send to the server to request the next page. Where I run into a stumbling block is when it comes to Ajax calls. There are number of drop down boxes that filter...
0
9671
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10845
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10549
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10254
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9376
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7792
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5828
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4019
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.