PDA

View Full Version : Does Anyone know a fix for the Mozilla sendAndLoad glitch?!


2Youth
02-02-2005, 08:39 PM
Hi everyone,

I am a new member in the forum but I have been using the archives a lot to find answers... But now I cannot find a good solution for this.
I am using sendAndLoad to send a question to php which queries a database and returns a string variable to flash (eg. echo "&my_var=".$my_var). This works fine in IE explorer but (as it is known) is very glitchy in Mozilla/Netscape/Safari.
I have tried using sendAndLoad specifying "POST", and "GET", with the same results: In Mozilla Firefox, and an older Mozilla (build ID 2005011116) the variables are sent and returned only the first time the browser is opened, or if the browser cache is cleared mmanually. On subsequent reloads, not only is the variable not recieved, but my whole flash movie seems to freeze up so I cant even print an error message.
I also tried not specifying the method at all ( eg. my_sentvar.sendAndLoad("myphpform.php", my_returnedvar) ) and, since I have heard that some browsers will default the method to "GET" and others to "POST", I included an if statement in my php when requesting the variable:
$question = $_POST['question'];
if(!$question){$question = $_GET['question'];}
not sure if this is a total noob thing to do, but it gives me interesting results:
In Mozilla Firefox, my variables are successfully sent and loaded approx. 6 out of 7 times ( the other time it freezes, and just says "waiting for www.whatever.com"). However, in the older version of Mozilla (which I think is similar to Safari), I still only get results the first time the browser is loaded.

Sorry for the long-winded explanation, without posting any code, but I am pretty sure this is a browser compatibility or caching problem. I have tried sending a Math.random() dummy var with my data (doesnt work), and have tried both "GET and "POST" (doesnt work).

Does anyone know a good fix for this? maybe a header to tell php what kind of data to expect (noob?!) or a header to prevent caching, or something, anything?

Thanx in advance,
2Youth
ps. I will post my code if it will help...

2Youth
02-02-2005, 10:15 PM
Hi, Me Again.
Um, tried testing more in Mozilla firefox using sendAndLoad without specifying either "POST" or "GET". I said it worked 6 out of 7 times - I lied. It pretty much works whenever it feels like it, which is actually more not than often.
I have been looking for solutions - putting:

header("Expires: Mon, 26 Jul 1997 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"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

into the php form doesn't work either. Anyone out there with any ideas would be appreciated. Also, if someone knows for sure there is no fix for this problem, let me know and I will have to go back to the drawing board...
Cheers,
2Youth

Dark_Element
02-03-2005, 06:49 AM
geesh mate... you are asking questions alreaidy? only 2 posts and are bost your first...

Whatever.... you can try passing a random dummy var with a random dummy value. or a random dummy var with a timestamp value (i doubt that will repeat itself lol)

Also your little php code that detects wheather if the var is passed through get or post... it will screw up if you have set the notices + warnings to "show all" and the var is not through POST, because PHP tend to give a notice when undefined values are attempted to be used (oviously you should know flash cant read this). so try changing it to this
$question = (isset($_POST['question']) ? $_POST['question'] : $_GET['question']);

2Youth
02-03-2005, 08:00 PM
Hey Dark Element,
Thanks for the response. I am new to this forum thing, am I supposed to try to answer other peoples forum questions before posting my own? I am not sure there are many people I could help...

Thanx for the suggestion, you may be right, the variable is not being passed to my php form and is considered undefined as opposed to empty. I tried using your code to check if the varable isset, but it didnt seem to change much. Another funny thing, in my actionscript code:
onLoad = function(){
var errorint = setInterval(function(){die()}, 1000);
var countdown = 10;
function die(){
error_txt.htmlText = countdown; countdown --;
if (countdown < 5){
clearInterval(errorint);
error_txt.htmlText="error" //+link to html version
}
var sendvars = new LoadVars();
sendvars.question = "getlist";
sendvars.dummy = Math.random();
var answer = new LoadVars();
var recarray = new Array();
sendvars.sendAndLoad("recordform.php", answer);
answer.onLoad = function()
{
if(answer.info)
{
recarray = answer.info.split('#');
for(i = 0; i < recarray.length-1; i++)
{
createduster(recarray[i])
}
}
else{error_txt.htmlText = 'temporarily unavailable';}
}
}
I have a function called by set interval to countdown and display an error message after five seconds (it is underneath what is loaded so will only show if no info is loaded). However (in Mozilla, IE works fine) the whole script freezes from the start and never even displays the countdown! The setInterval is not dependant on the sendAndLoad, and is initiated first in the script, so why would it fail?
Any suggestions how to figure out what is going on, the flashcode is obviously not being executed, I believe this a result of trying to continually execute the sendAndLoad with no result. The simplified php code is as follows:
<?php
header("Expires: Mon, 26 Jul 1997 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"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
$question = (isset($_POST['question']) ? $_POST['question'] : $_GET['question']);
$dummy = (isset($_POST['end']) ? $_POST['end'] : $_GET['end']);

if($question)
{
//connect, query, and echo '&info='.$result
}
else
{
echo '&info=error';
}

?>
I never get back any response, and the rest of the actionscript is not executed. In IE it works fine, but not Mozilla... Does Mozilla just not support the sendAndLoad method, and is there any way around it? Is there a way to view what is happening in the php file, retrieve a php error message as a variable?
Any suggestions are appreciated (and any advice on forum etiquette)
Thanx,
2Youth