• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 724
  • Last Modified:

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.
Paul Konstanski
Paul Konstanski
  • 4
1 Solution
Hi can you post your javacript function and <input.....>   tag  here so I can take look
Dave BaldwinFixer of ProblemsCommented:
Where is the database and what kind of database is it?
Paul KonstanskiProject SpecialistAuthor Commented:
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.

+++++++  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...



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">
<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(); 
		{// code for IE6, IE5
	  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 

	  		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
	    	document.getElementById("fttGroups").innerHTML=xmlhttp.responseText; }
	 //alert ('ajaxActs.php?a='+act+'i='str ); 
} // function makeFTT


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">
} // end if ($t == "")


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

<?php // ajaxAdmin.php 



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
	$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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Paul KonstanskiProject SpecialistAuthor Commented:
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.

Paul KonstanskiProject SpecialistAuthor Commented:
I resolved this issue myself.  It appears that there was no tag to close the table </ table> at the end an as such, the script failed on a Mac.  

I no longer need an answer to this question.
Paul KonstanskiProject SpecialistAuthor Commented:
I realized that there was no close table tag and although that was okay on the PC the Mac didn't like it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now