call page using AJAX

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

call page using AJAX

Post by bouncer »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


hi.

i'm using this line to include a php page into a "main" one

Code: Select all

require_once 'verConfig.php';
but verConfig.php have included a "refresh" button that call this javascript function

Code: Select all

<script type="text/javascript">

function refreshConfig (cfg) {
	size = document.config.elements.length;
	ctent = "";
	for (i=1; i < size; i++){
		ctent = ctent + document.config.elements[i].value +",";	
	}
	
	ctent = ctent.substr(0,ctent.length-1);

	if ( value ) {
		location.href = "verConfig.php?c=<?=$c?>&calc=2&arrProd="+ctent;
	} else {
		location.href = "verConfig.php?c=<?=$c?>&calc=1&arrProd="+ctent;
	}
}

</script>
this function will call the same page and pass those values into it, but now i have the verConfig.php page included into another page. the problem is that if a call refreshConfig function the "main" page will disapper and the verConfig.php is the one left.

so i'm trying to solve this problem using ajax, is there any way to use this to call the page again, without refreshing the "main" page only the included one (verConfig.php) ??

Code: Select all

function GetXmlHttpObject() {
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
    } catch (e) {
	// Internet Explorer
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
    }
	return xmlHttp;
}

function updatePage() {
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    document.getElementById("element").value = response;
  }
}

function calcConfig(...) {
	try {

                           size = document.config.elements.length;
	           ctent = "";
	           for (i=1; i < size; i++){
	                ctent = ctent + document.config.elements[i].value +",";	
	           }
	
	           ctent = ctent.substr(0,ctent.length-1);

		if ( value ) {
		     location.href = "verConfig.php?c=<?=$c?>&calc=2&arrProd="+ctent;
	                } else {
		     location.href = "verConfig.php?c=<?=$c?>&calc=1&arrProd="+ctent;
	                }

		xmlHttp.onreadystatechange = updatePage;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	} catch (e) { }
}
this is the only idea that i have, if someone have a better one please reply :)

thanks in advance


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

Does that work?? If not, what happens?
thewebdrivers
Forum Commoner
Posts: 41
Joined: Fri Aug 17, 2007 3:32 pm
Location: india
Contact:

Post by thewebdrivers »

in the first example, you can change

Code: Select all

if ( value ) {
      location.href = "verConfig.php?c=<?=$c?>&calc=2&arrProd="+ctent;
   } else {
      location.href = "verConfig.php?c=<?=$c?>&calc=1&arrProd="+ctent;
   }
to

Code: Select all

if ( value ) {
      location.href = "mainpage.php?c=<?=$c?>&calc=2&arrProd="+ctent;
   } else {
      location.href = "mainpage.php?c=<?=$c?>&calc=1&arrProd="+ctent;
   }
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

califdon wrote:Does that work?? If not, what happens?
no, it doesn't work, was just an example to give you an idea on what i'm trying to do.
thewebdrivers wrote: in the first example, you can change

Code: Select all

Code: 
if ( value ) { 
      location.href = "verConfig.php?c=<?=$c?>&calc=2&arrProd="+ctent; 
   } else { 
      location.href = "verConfig.php?c=<?=$c?>&calc=1&arrProd="+ctent; 
   }
to

Code: Select all

Code: 
if ( value ) { 
      location.href = "mainpage.php?c=<?=$c?>&calc=2&arrProd="+ctent; 
   } else { 
      location.href = "mainpage.php?c=<?=$c?>&calc=1&arrProd="+ctent; 
   }
that seems to work but i'm not getting the value of calc and arrProd :(

thanks in advance
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Post by bouncer »

now is working thank you for your help :D

now i will try to make this in a better way using ajax :wink:

regards
Post Reply