Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


AJAX Not posting on MAC OS

Posted on 2010-11-18
Medium Priority
Last Modified: 2013-11-12
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.
Question by:pkonstan1
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4

Expert Comment

ID: 34170766
Hi can you post your javacript function and <input.....>   tag  here so I can take look
LVL 84

Expert Comment

by:Dave Baldwin
ID: 34170901
Where is the database and what kind of database is it?

Author Comment

ID: 34175843
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 );"GET","ajaxMac.php?a=ftt&i="+str,true);
} // 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

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!


Author Comment

ID: 34175863
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.


Accepted Solution

pkonstan1 earned 0 total points
ID: 34182039
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.

Author Closing Comment

ID: 34211384
I realized that there was no close table tag and although that was okay on the PC the Mac didn't like it.

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to dynamically set the form action using jQuery.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

661 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question