Link to home
Start Free TrialLog in
Avatar of Isaac
IsaacFlag for United States of America

asked on

AJAX Problem continuation

Hello,


I used the exact same ajax code(https://www.experts-exchange.com/questions/23504279/AJAX-Problem.html) at my job and it works fine except that after I enter in my comments and click "Update" the comment does not appear.  I have to hit refresh to see my changes.  I have been struggling with it all morning.
var xmlHttp=null; 
 
 function editComment(id) 
{ 
	xmlHttp=GetXmlHttpObject(); //See if it works with users browser. 
	if (xmlHttp==null) 
	{ 
		alert ("Browser does not support HTTP Request"); 
		return false; 
	} 
  xmlHttp.onreadystatechange=function(){stateChanged(id);}
	var url="schedAjax.asp"; 
	var data = "edtShed=Yes&cm_id="+id+"&cmt="+encodeURIComponent( document.getElementById("cmt"+id).value ); 
	xmlHttp.open("POST",url,true); 
	xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	xmlHttp.setRequestHeader("Content-length", data.length); 
  xmlHttp.send( data ); 
}
 
 
function stateChanged(id) 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 { 
 document.getElementById("showCmt"+id).innerHTML=xmlHttp.responseText 
 hideEdit(id);
 } 
}
 
 
function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
 
  return xmlHttp;
}
 
 function show(id)
 {
 	document.getElementById(id).style.display="";
 }
 function hide(id)
 {
 	document.getElementById(id).style.display="none";
 }
 
 function showEdit(id)
 {
		show('cmt'+id);
    show('Update'+id);
    hide('Edit'+id);
    hide('showCmt'+id);
 }
 function hideEdit(id)
 {
		hide('cmt'+id);
    hide('Update'+id);
    show('Edit'+id);
    show('showCmt'+id);
 }
 
 
<!------------------------------------------------------------------------------------------------------------->            
<DIV>                     
<TABLE>
CODE.....
 
           <%
	           Set rs=Server.CreateObject("ADODB.Recordset") 
	           sSQL = "SELECT * FROM misComment WHERE ID = " & CLng(d) & " ORDER BY vDATE DESC"
	           rs.Open sSQL, objConn
	           do while not rs.EOF
           %>
             
             <form>
             <tr>
               <td width="10%"><%=rs("vdate")%></td>
               <td width="10%"><%=rs("usr")%></td>    
               <td>
               	<span id="showCmt<%=rs("id")%>">
               		<%=rs("comment")%>
               	</span>
               		<textarea style="display:none" id="cmt<%=rs("id")%>" cols="50" rows="5"><%=rs("comment")%></textarea>
               </td>
					     <td>
					     		<input type="button" id="Edit<%=rs("id")%>" value="Edit" onclick="showEdit('<%=rs("id")%>')"  name="edit" />
					     		<input type="button" value="Update" name="edit" id="Update<%=rs("id")%>" style="display:none;" onclick="editComment('<%=rs("id")%>')"  /></td>
             </tr>
             </form>
             
             <%
					    rs.MoveNext
			    		Loop
    				 %>
 
MORE CODE-----
</TABLE>
</DIV>
<!------------------------------------------------------------------------------------------------------------->

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Isaac

ASKER

Hielo,

You are a life saver.  Thanks!!!
Avatar of Isaac

ASKER

Hielo is excellent at AJAX.
Your code and explanations make sense.
Thanks.
You are welcome!
Avatar of Isaac

ASKER

Hello Hielo,

I hope all is well.  I have an Ajax problem that I or anyone else can seem to solve.  It's similar to this post except that it's with PHP instead of ASP.  Do you mind taking a look at it?  It's located here:
https://www.experts-exchange.com/questions/23986253/ajax-not-working-right.html

You were the only one I could think of that could solve this problem.  Please help if you can.  Thanks.