Solved

AJAX Not posting on MAC OS

Posted on 2010-11-18
6
714 Views
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.
0
Comment
Question by:pkonstan1
[X]
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
6 Comments
 
LVL 2

Expert Comment

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

Expert Comment

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

Author Comment

by:pkonstan1
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.

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

0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 

Author Comment

by:pkonstan1
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.


0
 

Accepted Solution

by:
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.
0
 

Author Closing Comment

by:pkonstan1
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.
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

726 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