Solved

AJAX Not posting on MAC OS

Posted on 2010-11-18
6
708 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
  • 4
6 Comments
 
LVL 2

Expert Comment

by:karthi4all
Comment Utility
Hi can you post your javacript function and <input.....>   tag  here so I can take look
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
Where is the database and what kind of database is it?
0
 

Author Comment

by:pkonstan1
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:pkonstan1
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now