Jump to content

Ajax refresh/reload


cesarcesar

Recommended Posts

Im using this script, http://www.captain.at/howto-ajax-form-post-get.php, to make an ajax request to php via a drop-down (DD) select. This works fine. Then using this script, http://www.dhtmlgoodies.com/index.html?whichScript=ajax-dynamic-content, i request to show a php page with other form elements in it. These elements are determined by what the first DD of the first request (captain.at) sets a variable to. This works fine.. only the first time though. What seems to be happening is that even though each time a DD option is selected, the variable changes as it should, but when the second script fires it still shows the previous variable. Its like the div is not reloading the page with new vars set, its just showing the page it first ran. I have tried to make another call to show a different page, this works for clearing content of the div, which i want, but not making the div reload with a page using fresh vars. I hope i got my point across.

 

My main question i think is, how, when i call the dhtmlgoodies script, can i get the div/page to show using the newest variable? Here is some stripped out important code.

 

index.php

<select id="sale_type_id" name="sale_type_id" onmousedown="ajax_loadContent('search','ajax_search_blank.php');" onchange="makeRequest('ajax_search.php?sti=',this.value);ajax_loadContent('search','ajax_search.php');">

<? $_stt = db_query("SELECT sale_type_id, sale_type_name FROM sale_type WHERE sale_type_id <> 43 ORDER BY sale_type_name ASC");
while($stt = db_fetch_array($_stt)) { ?>
	<option value="<?php pv($stt['sale_type_id']); ?>"><?php pv($stt['sale_type_name']); ?></option>
<? } ?>

</select>

<p>

<DIV id="search"></DIV>

 

ajax_search.php

<? 
/*   set the sale_type id for the search drop down.   */
if(isset($_GET['sti'])) {

$_SESSION['sti'] = $_GET['sti'];

}elseif(isset($_SESSION['sti'])) { 

$_stt = db_query("
Select distinct
sale_type_field.sale_type_field_name,
sale_type_field.sale_type_field_id
From
sale_type_field
JOIN connector_sale_type_field ON sale_type_field.sale_type_field_id = connector_sale_type_field.sale_type_field_id
Where
connector_sale_type_field.sale_type_id = '".$_SESSION['sti']."'
ORDER BY
sale_type_field.sale_type_field_name ASC
");
while($stt = db_fetch_array($_stt)) {
	$sale_type_field_id[] = $stt['sale_type_field_id'];
	$sale_type_field_name[] = $stt['sale_type_field_name'];
} ?>

<select name="search_field[]">
	<option value=""></option>
	<option value="sale_id">Sale Id</option>

	<?php for ($j = 0; $j < count($sale_type_field_name); $j++) { ?>

		<option value="<?php pv($sale_type_field_id[$j]); ?>"><?php pv($sale_type_field_name[$j]); ?></option>

	<?php } ?>

</select>

<?php } ?>

 

Link to comment
Share on other sites

I think you are having a similar problem that I was just having. I came here to find the answer but seeing as it has not been answered I had to figure it out for myself.

 

My Problem:

 

I had three test pages that I would load with AJAX. Once I loaded page 1, if I went to another page and tried to go back to page 1 it would not reload the page, it would just go with what it had stored in the temporary internet files. Well I couldn't have this because my site is constantly being updated by members.

 

My Solution:

 

I found out that it would reload the page if I put a bogus variable at the end (example: page.php?time=110234) as long as the next time I load the page the variable was different. I used a javascript time function to update the links every second so each time a link was clicked it would reload the page.

 

Javascript in header:

<script>
<!--
/*
By George Chiang (WA's JavaScript tutorial) 
http://wsabstract.com
*/

function show2(){
  var Digital=new Date()
  var hours=Digital.getHours()
  var minutes=Digital.getMinutes()
  var seconds=Digital.getSeconds()
  var dn="AM" 

  if (hours>12){
   dn="PM"
   hours=hours-12
  }

  if (hours==0)
   hours=12

  if (minutes<=9)
   minutes="0"+minutes

  if (seconds<=9)
   seconds="0"+seconds
   var ctime=hours+""+minutes+""+seconds+" "+dn
   tick2.innerHTML="  <a href=\"javascript:void(0);\" onclick=\"changePage('home.php?time="+ctime+"');\">Home</a>    -    <a href=\"javascript:void(0);\" onclick=\"changePage('content.php?page=2&time=1'+minute+second);\">Another Page</a>    -    <a href=\"javascript:void(0);\" onclick=\"changePage('content.php?page=2&time="+ctime+"');\">Another Page</a> ----"+ctime+"</b>"
   setTimeout("show2()",1000)
}

window.onload=show2
//-->
</script>

 

Where I have the links:

<span id=tick2></span>

 

As you can see I just grabbed a simple function off of some website. This worked for me, I hope it works for you too!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.