943,755 Members | Top Members by Rank

Ad:
Sep 13th, 2008
0

Ajax script not working on firefox

Expand Post »
Hi all

i have this problem with my ajax script that it is working with IE but not on firefox.this script is updating database. following is AJAX Script::
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. function ajaxpost(){
  3. var mypostrequest;
  4. try
  5. {
  6. // Firefox, Opera 8.0+, Safari
  7. mypostrequest = new XMLHttpRequest();
  8. }
  9. catch (e)
  10. {
  11. // Internet Explorer
  12. try
  13. {
  14. mypostrequest = new ActiveXObject("Msxml2.XMLHTTP");
  15. }
  16. catch (e)
  17. {
  18. mypostrequest = new ActiveXObject("Microsoft.XMLHTTP");
  19. }
  20. }
  21. mypostrequest.onreadystatechange=function(){
  22. if (mypostrequest.readyState == 4) {
  23. res = mypostrequest.responseText; // These following lines get the response and update the page
  24. document.getElementById('result').innerHTML = res;
  25. //document.getElementById('result').value = res;
  26. }
  27. }
  28.  
  29. var parameters =
  30. "client="+encodeURI(document.getElementById("client").value)+
  31. "&user="+encodeURI(document.getElementById("user").value)+
  32. "&frmtim="+encodeURI(document.getElementById("frmtim").value)+
  33. "&totim="+encodeURI(document.getElementById("totim").value)+
  34. "&title="+encodeURI(document.getElementById("title").value)+
  35. "&type="+encodeURI(document.getElementById("type").value)+
  36. "&desc="+encodeURI(document.getElementById("desc").value)+
  37. "&date="+encodeURI(document.getElementById("date").value);
  38. var url = "https://client.extremescreamproductions.com/leads/ajaxpost.php";
  39. mypostrequest.open("POST", url, true);
  40. mypostrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  41. mypostrequest.setRequestHeader("Content-length", parameters.length);
  42. mypostrequest.setRequestHeader("Connection", "close");
  43. mypostrequest.send(parameters);
  44. }
  45. </script>

HTML page is::
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <form method = "post"action="" id="action_time">
  2. <table>
  3. <tr><td>Client</td><td><input name="client" type="text" id="client" value="<% print $hname; %>"/> </td>
  4. <td>User</td><td><input name="user" type="text" id="user"
  5. value="<% print $auth->auth[first_name]." ".$auth->auth[last_name]; %>"/> </td></tr>
  6. <tr><td>From</td><td><input name="frmtim" type="text" id="frmtim" maxlength="8" value="<?php echo $cur_time;?>"/></td>
  7. <td>To</td><td><input name="totim" type="text" id="totim" maxlength="8"/></td></tr>
  8. <tr><td>Title</td><td><input name="title" type="text" id="title"/> </td>
  9. <td>Type</td><td><select name="type"><option id="opt1" value="type1">Type 1</option>
  10. <option id="opt2" value="type2">Type 2</option>
  11. <option id="opt3" value="type3">Type 3</option>
  12. <option id="opt4" value="type4">Type 4</option>
  13. </select> </td><td></td><td></td></tr>
  14. <tr><td>Description</td><td colspan="3"><textarea name="desc" id="desc" rows="5" cols="15">description goes here</textarea> </td></tr>
  15. <tr><td>Date</td><td><input name="date" id="date" size="15" value="<?php echo $cur_date;?>"></td> <td colspan="2">
  16. <input type="submit" value="Submit" name ="post_time" id="actiontime" class="buttons" onClick="ajaxpost(); return false;"/></td></tr>
  17. </table></form>

PHP Script (ajaxpost.php)::
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <?php
  2. $client = $_POST['client'];
  3. $user = $_POST['user'];
  4. $frmtim = $_POST['frmtim'];
  5. $totim = $_POST['totim'];
  6. $title = $_POST['title'];
  7. $type = $_POST['type'];
  8. $desc = $_POST['desc'];
  9. $date = $_POST['date'];
  10. $databasehost = "localhost";
  11. $databasename = "db";
  12. $databaseusername ="user";
  13. $databasepassword = "pass";
  14. $con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
  15. @mysql_select_db($databasename) or die(mysql_error());
  16.  
  17. list($h1,$m1,$s1)=split(":",$frmtim);
  18. list($h2,$m2,$s2)=split(":",$totim);
  19. if($h1 > $h2){
  20. $second1=$s1+($h1*3600)+($m1*60);//converting it into seconds
  21. $second2=$s2+($h2*3600)+($m2*60);
  22. }else{
  23. $second2=$s1+($h1*3600)+($m1*60);//converting it into seconds
  24. $second1=$s2+($h2*3600)+($m2*60);
  25. }
  26. if ($second1==$second2)
  27. {
  28. $total_tim="00:00:00";
  29. }
  30. if ($second1<$second2) //
  31. {
  32. $second1=$second1+(24*60*60);//adding 24 hours to it.
  33. }
  34. $second3=$second1-$second2;
  35. //print $second3;
  36. if ($second3==0)
  37. {
  38. $h3=0;
  39. }
  40. else
  41. {
  42. $h3=floor($second3/3600);//find total hours
  43. }
  44.  
  45. $remSecond=$second3-($h3*3600);//get remaining seconds
  46. if ($remSecond==0)
  47. {
  48. $m3=0;
  49. }
  50. else
  51. {
  52. $m3=floor($remSecond/60);// for finding remaining minutes
  53. }
  54.  
  55. $s3=$remSecond-(60*$m3);
  56.  
  57. if($h3==0)//formating result.
  58. {
  59. $h3="00";
  60. }
  61. if($m3==0)
  62. {
  63. $m3="00";
  64. }
  65. if($s3==0)
  66. {
  67. $s3="00";
  68. }
  69. $totaltime = 0;
  70. $th = 0;
  71. $tm = 0;
  72. $ts = 0;
  73. $total_tim = "$h3:$m3:$s3";
  74. $pkstr = $frmtim;
  75. $pkstr .= $date;
  76. $pkstr .= $user;
  77. $pk = md5("$pkstr");
  78. $insert_query="insert into actiontime values('$pk','$client','$user','$total_tim','$title','$type','$desc','$date');";
  79. @mysql_query($insert_query,$con);
  80. $sel_query = "select total_time from actiontime where client ='$client' AND user = '$user';";
  81. $result = @mysql_query($sel_query,$con);
  82. while($values = mysql_fetch_array($result)){
  83. $a = $values['total_time'];
  84. list($h,$m,$s)=split(":",$a);
  85. $th = $th + $h;
  86. $tm = $tm + $m;
  87. $ts = $ts + $s;
  88. }
  89. $second=$ts+($th*3600)+($tm*60);
  90. $th=floor($second/3600);//find total hours
  91. $remSecond=$second-($th*3600);//get remaining seconds
  92. $tm=floor($remSecond/60);// for finding remaining minutes
  93. $ts=$remSecond-(60*$tm);
  94. $totaltime = "Hr:$th Min:$tm Sec:$ts";
  95. echo $totaltime;
  96. ?>

i get no error on firefox.
i have tried it on firefox 2.0 and 3.0 as well.Please help

Thanks a million in advance
jyoti u
Last edited by jyotiu; Sep 13th, 2008 at 3:06 pm.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
jyotiu is offline Offline
33 posts
since Sep 2008
Sep 14th, 2008
0

Re: Ajax script not working on firefox

Hi.

I see two problems.

First, the <select> box is missing the ID attribute.
IE incorrectly uses the name attribute when an ID tag is missing, which explains why this works in IE.

Also, the <input type="submit"> button should not be used to trigger scripts like that. Unlike the onsubmit event of the <form> element, if the <input> onclick event returns false, as it does in your script, the form could still be submitted.
(IE and Firefox apparently do stop it tho.)

To fix that, try changing the <input type="submit"> to <input type="button"> . That should just trigger the script.
Last edited by Atli; Sep 14th, 2008 at 4:09 am.
Reputation Points: 93
Solved Threads: 70
Posting Pro
Atli is offline Offline
526 posts
since May 2007
Sep 15th, 2008
0

Re: Ajax script not working on firefox

Thanks a lot !!!!
It worked....you r an angel to me.
Reputation Points: 10
Solved Threads: 0
Light Poster
jyotiu is offline Offline
33 posts
since Sep 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Currency usage in calculator form
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: populating text field in firefox not working





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC