jwk811 Posted September 17, 2010 Share Posted September 17, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/213634-what-the-heck-ajax-request-only-working-once-in-a-while/ Share on other sites More sharing options...
ngreenwood6 Posted September 17, 2010 Share Posted September 17, 2010 Can we see some of your code? Kinda hard to troubleshoot without anything to look at. Quote Link to comment https://forums.phpfreaks.com/topic/213634-what-the-heck-ajax-request-only-working-once-in-a-while/#findComment-1111958 Share on other sites More sharing options...
jwk811 Posted September 17, 2010 Author Share Posted September 17, 2010 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>";?> Quote Link to comment https://forums.phpfreaks.com/topic/213634-what-the-heck-ajax-request-only-working-once-in-a-while/#findComment-1111961 Share on other sites More sharing options...
ngreenwood6 Posted September 17, 2010 Share Posted September 17, 2010 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);"> Quote Link to comment https://forums.phpfreaks.com/topic/213634-what-the-heck-ajax-request-only-working-once-in-a-while/#findComment-1111963 Share on other sites More sharing options...
ngreenwood6 Posted September 17, 2010 Share Posted September 17, 2010 Also you can take out all that headers crap its not needed. Quote Link to comment https://forums.phpfreaks.com/topic/213634-what-the-heck-ajax-request-only-working-once-in-a-while/#findComment-1111964 Share on other sites More sharing options...
jwk811 Posted September 17, 2010 Author Share Posted September 17, 2010 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? Quote Link to comment https://forums.phpfreaks.com/topic/213634-what-the-heck-ajax-request-only-working-once-in-a-while/#findComment-1111971 Share on other sites More sharing options...
jwk811 Posted September 17, 2010 Author Share Posted September 17, 2010 it works 9 outta 10 times now. so uhh i guess i can deal with it for now. if you have any other suggestions let me know thanks for your help =] Quote Link to comment https://forums.phpfreaks.com/topic/213634-what-the-heck-ajax-request-only-working-once-in-a-while/#findComment-1111973 Share on other sites More sharing options...
gamesmstr Posted September 17, 2010 Share Posted September 17, 2010 I think I know what your problem is. You are using the same ajax request function (xmlhttp) to update 2 different targets an the same page. I had the same problem with my chat page. Create a separate function for each (ie. xmlhttp and xmlhttp2) and your issue will probably disappear. Quote Link to comment https://forums.phpfreaks.com/topic/213634-what-the-heck-ajax-request-only-working-once-in-a-while/#findComment-1112236 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.