Ajax script not working on firefox

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Sep 2008
Posts: 33
Reputation: jyotiu is an unknown quantity at this point 
Solved Threads: 0
jyotiu jyotiu is offline Offline
Light Poster

Ajax script not working on firefox

 
0
  #1
Sep 13th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 418
Reputation: Atli is on a distinguished road 
Solved Threads: 53
Atli's Avatar
Atli Atli is offline Offline
Posting Pro in Training

Re: Ajax script not working on firefox

 
0
  #2
Sep 14th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 33
Reputation: jyotiu is an unknown quantity at this point 
Solved Threads: 0
jyotiu jyotiu is offline Offline
Light Poster

Re: Ajax script not working on firefox

 
0
  #3
Sep 15th, 2008
Thanks a lot !!!!
It worked....you r an angel to me.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC