Link to home
Start Free TrialLog in
Avatar of Paul Konstanski
Paul KonstanskiFlag for United States of America

asked on

AJAX Not posting on MAC OS

I have a php application that uses ajax and javascript to update a hidden field.  It works fine on a PC but it doesn't work on a MAC.  

Here's how it works.  When a person enters in a new code in a box, there is an "onChange" parameter that calls up "xmlhttp.onreadystatechange=function()"

This then calls another .php page that does a DB query to find if the number is valid and to return the description associated with that number.  It then updates a "hidden" post field with that number.  If a second code number is entered in the box it repeats the process and appends the new code number to the end of the old separated by a colon.  When all the codes have been enter, you hit submit.

On a PC this works great.  It correctly saves the hidden field into the database (i.e. the correct values show up in the http POST).  But on a MAC, the hidden field is empty.  As a test, I changed it from a hidden to a "text" field and in both cases, the on screen values are correct.  In other words, even on the MAC it is correctly updating the field via the onChange javascript.

But then somewhere between the "Submit" and the arrival at the new page, the value for the field is reset to blank (which is the default value for when it comes in).  This only happens on the MAC.  So how is it that the post works great on a PC but not on a MAC?  

Insight would be appreciated.
Avatar of karthi4all
karthi4all

Hi can you post your javacript function and <input.....>   tag  here so I can take look
Avatar of Dave Baldwin
Where is the database and what kind of database is it?
Avatar of Paul Konstanski

ASKER

Sorry for delayed reply.  The code that is not working is a few lines in the middle of massive scripts.  So I spent some time to reduce this down to the smallest clear code that shows the issue.  

The result is two files (or code sections).  

The first is called macTest.php.  This is the main input form/response form.  When you first arrive, it basically gives a box for entering in single digits (1-5).  Using Ajax scripting, those numbers are placed/appended to a field that should post.

The second is called ajaxMac.php.  This is the ajax file that is called from the other script.  This is the one that actually does the "building" of the 3ftt field.  

This script works fine on a PC but doesn't work on a MAC.  I'm trying to find why that is so.  You should be able to cut/paste the following code into two files as named and try this on your own machine provided that it runs php scripts.

Thanks.
+++++++  The following is the first file called macTest.php  +++
<?php #macTest.php
 // These lines are what control the initial landing form...
 // the $myResp array and the $userLine variables come from a previous database read...

session_start(); 

$t=$_GET["t"];

if ($t == "postResponse") {
	print 'These are the postVariables:<br />If this is working correctly, there should be a listing for a field
	called <b>3ftt</b>.  If it is missing, something is going wrong with the script.<br /><br />';
	foreach ($_POST as $key => $value) {
		print '<b>'.$key.'</b>: '.$value.'<br />';
	} // end foreach ($_POST as $key => $value) {
	print '<br /><hr size=3 color="tan" width="500"><br /><br />';
	if ($_POST['3ftt'] > "" && $_POST['3ftt'] != "empty")print '<b><font color="green">Success</font></b>: The field posted correctly</b>';
	  else print '<b><font color="red">Failure</font></b>: It did not take any of your numbers.<br /><br />';
	print '<br /><br /><a href="macTest.php">Restart</a>';
} // if ($t == "postResponse") {
 
// this is where the HTML begins...
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>MAC Not Post Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script language="javascript">

function makeFTT(str) {
	var newtot = parseInt(document.response.calc.value) + parseInt(1);
	document.response.calc.value = newtot;
	document.response.newFTT.value = "";
//	alert (' NEW cur value is [ ' + cur + ' ] ');
	
	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("fttGroups").innerHTML=xmlhttp.responseText; }
	  	}
	 //alert ('ajaxActs.php?a='+act+'i='str ); 
	xmlhttp.open("GET","ajaxMac.php?a=ftt&i="+str,true);
	xmlhttp.send();
	document.response.newFTT.focus();
} // function makeFTT


</script>
</head>    
<body>

<?
 
if ($t == "") { // for new entry, give blank form
	$_SESSION['thisFTT'] = "";
	$d1 = array("0", "3");
	$d3 = "";
	
	print '<div><table width=500 cellspacing="3">';
	print '<form name="response" action="macTest.php?t=postResponse" method="post">';
	print 'Enter a number between and including 1-5 in the "<b><font color="plum">Insert New FTT#</font>: </b> field.  Then hit "Add".  Then try it with a second or third number.
		   As you enter these numbers and hit ADD, it should build a display entry with <font color="blue">blue text</font> and the 
		   <font color="red">3ftt box</font> should be building with your numbers colon separated.  Hit submit after you have entered a few. The 
		   "calculated" field should be recording your entries as well.<br /><br />'; 
	print 'Field Test One: 
		   Calculated: <input type="text" size="5" name="calc" value="'.$d1[0].'"  onkeydown="return false;">&nbsp;&nbsp;
			Override Commit: <input type="text" size="5" name="over" value="'.$d1[1].'"><br />
			<font color="plum">Insert New FTT#</font>: <input type="text" width="5" size="5" name="newFTT" value="" onchange="makeFTT(this.value)">
		   <input type="button" name="doFTT" value="Add"> (Values 1-5) <br />
			<font color="blue"><div id="fttGroups"><br /><b><font color="red">3ftt Field</font>: <input type="text" name="3ftt" value="empty"></div></font><br />';
 
	?> <tr><td colspan="2" align="center"><hr size="3" color="#990000">
		<input type="submit" name="responseIn" value="Submit"> &nbsp;&nbsp;
		<input type="submit" name="responseIn" value="Cancel">
	   </td></tr>
	  </form></div><?
} // end if ($t == "")

?>
</body>
</html>


+++++  The following is the second file called ajaxMac.php  +++

<?php // ajaxAdmin.php 

session_start(); 

$a=$_GET["a"];
$i=$_GET["i"];

if ($_SESSION['FTT'] == "") { // this loads up the session for the first time.
	$_SESSION['FTT'] = array(
						  "1" => "One",
						  "2" => "Two",
						  "3" => "Three",
						  "4" => "Four",
						  "5" => "Five");
} // if ($_SESSION['FTT'] == "") { // this loads up the session

if ($a == "ftt") {
	$d2 = array();
	if ($_SESSION['thisFTT'] > "") {
		$dupMsg = "";
		foreach ($_SESSION['thisFTT'] as $item) {
			if ($i == $item) $dupMsg = ' || <font color="red">FTT <b>'.$i.'</b> already entered. ';
			$d2[] = $item; // build your array
		} // foreach ($_SESSION['thisFTT'] as $item) {
	} // end if ($_SESSION['thisFTT']) > "") {
	if ($dupMsg == "") $d2[] = $i; // if no duplicate, then add to array
	$FTT = $_SESSION['FTT'];
	$FTTdesc = "";
	foreach ($d2 as $item) {
		if ($FTT[$item]['PG'] > "") $desc = $FTT[$item]; else $desc = '<font color="tan"><b>out of range</b></font>';
		if ($item > "") $FTTdesc .= $item.' => '.$desc. ' || ';
	} // end foreach ($d2 as $item)
	$newFTT = implode(":",$d2);
	$FTTdesc = rtrim($FTTdesc, ' || ').$dupMsg.'<br />3ftt Field: <input type="text" name="3ftt" value="'.$newFTT.'">';
	$_SESSION['thisFTT'] = $d2; // this resets the session variable
	print $FTTdesc;
} // end if ($a == "ftt") {

?>

Open in new window

Although my original script did make a Database Call as a part of the ajax process, this updated script that has been stripped to the bare minimum no longer makes a DB call and it still has the problem.

So thus the DB question from DaveB is not a factor in this case.


ASKER CERTIFIED SOLUTION
Avatar of Paul Konstanski
Paul Konstanski
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I realized that there was no close table tag and although that was okay on the PC the Mac didn't like it.