Jump to content

WHAT THE HECK! Ajax request only working once in a while??


jwk811

Recommended Posts

This is so frustrating, I don't understand why this might be happening. I have a select form input that uses onchange to send a ajax request to show the data.

 

It works. Then I click again it doesnt work, click another select option it works, then back to the other works, then the next doesnt then doesnt then doesnt then does... sorry it just seems so random there are only 2 options right now and they work every like 4 clicks going back and forth on average.

 

There has to be an explaination, how can I fixed this. I googled it and read something about caching which makes no sense and I added the headers like it said:

 

 

header("Expires: Sun, 19 Nov 1978 05:00:00 GMT");

header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");

header("Cache-Control: no-store, no-cache, must-revalidate");

header("Cache-Control: post-check=0, pre-check=0", false);

header("Pragma: no-cache");

 

to the php page. Please save me from this frustration please.

Link to comment
Share on other sites

part of the form:

 

 

        <td width="100%"><select name="select_workout_routine" id="select_workout_routine" onchange="javascript:showWorkoutInfo(this.value);"><option value="0" selected>-----Choose Your Full Body Routine-----</option><?php$sql = "SELECT id, workout_name FROM user_workouts WHERE workout_type = 'full' AND user_id = '0'";$result = dbQuery($sql);while ($row = dbFetchAssoc($result)){extract($row);echo "<option value=\"" . $id . "\">";echo $workout_name;echo "</option>";}?></select><br><br></td>

 

 

the javascript:

 

 

function showWorkoutInfo(str){if (str=="")  {  document.getElementById("workoutRoutines").innerHTML="";  return;  }if (window.XMLHttpRequest)  {// code for IE7+, Firefox, Chrome, Opera, Safari  xmlhttp=new XMLHttpRequest();  }else  {// code for IE6, IE5  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }xmlhttp.onreadystatechange=function()  {  if (xmlhttp.readyState==4 && xmlhttp.status==200)    {    document.getElementById("workoutRoutines").innerHTML=xmlhttp.responseText;    }  }xmlhttp.open("GET","getInfo.php?id="+str,true);xmlhttp.send();}

 

 

getInfo.php

 

 

<?phpheader("Expires: Sun, 19 Nov 1978 05:00:00 GMT");header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");header("Cache-Control: no-store, no-cache, must-revalidate");header("Cache-Control: post-check=0, pre-check=0", false);header("Pragma: no-cache");include '../lib/config.php';$id = $_GET['id'];echo "<span style=\"color:white;\"><b>MUSCLE ORDER: <select name=\"\" id=\"\">";$sql = "SELECT id AS order_id, order_name FROM workout_routine_order WHERE id = '$id'";$result = dbQuery($sql);while ($row = dbFetchAssoc($result)){extract($row);echo "<option value=\"" . $order_id . "\">";echo $order_name;echo "</option>";}echo "</select></b></span><br><table>";$sql = "SELECT id AS order_id, order_name FROM workout_routine_order WHERE id = '$id' LIMIT 1";$result = dbQuery($sql);$row = dbFetchAssoc($result);$first_id = $row['order_id'];$sql = "SELECT *, id AS exercise_id FROM workout_exercises WHERE workout_id = '$id' AND order_id = '$first_id' ORDER BY ex_order ASC";$result = dbQuery($sql);while ($row = dbFetchAssoc($result)){extract($row);echo "<tr>";echo "<td width=\"40%\"><input type=\"checkbox\" name=\"\" id=\"\" value=\"";echo $exercise_id;echo "\" checked><label for=\"\"><b>";echo $ex_muscle;echo "</b></label></td>";echo "</tr>";}echo "</table>";?>

 

Link to comment
Share on other sites

I think that this line may be the problem:

 

 

<select name="select_workout_routine" id="select_workout_routine" onchange="javascript:showWorkoutInfo(this.value);">

 

 

You dont need the javascript: part there but that shouldnt be breaking it. I think it is the this.value part that is. try changing that line to this:

 

 

<select name="select_workout_routine" id="select_workout_routine" onchange="showWorkoutInfo(this[this.selectedIndex].value);">

 

Link to comment
Share on other sites

i put that and i tried it and i was like wow that worked. and i kept switching to different options and it worked like 9 times in a row then it started not working again and sometimes even the data is from a different table which makes no sense. its the other ajax i have in the javascript for the chat.

 

so thanks i think its a little bit better now? lol but still same problem just not as bad haha wow this makes no sense any other suggestions?

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.