Page 1 of 1

call page using AJAX

Posted: Tue Aug 28, 2007 6:02 am
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]

Posted: Tue Aug 28, 2007 12:41 pm
by califdon
Does that work?? If not, what happens?

Posted: Tue Aug 28, 2007 1:07 pm
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;
   }

Posted: Wed Aug 29, 2007 3:56 am
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

Posted: Wed Aug 29, 2007 4:58 am
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