Solved

AJAX Problem continuation

Posted on 2008-06-23
5
263 Views
Last Modified: 2010-04-21
Hello,


I used the exact same ajax code(http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_23504279.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

0
Comment
Question by:Isaac
[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
  • 3
  • 2
5 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 21847618
You are sending the edits to schedAjax.asp. schedAjax.asp MUST echo back the comment.  So, the last statement in schedAjax.asp
should be:
Response.Write( Request("cmt") )
0
 
LVL 5

Author Comment

by:Isaac
ID: 21848369
Hielo,

You are a life saver.  Thanks!!!
0
 
LVL 5

Author Closing Comment

by:Isaac
ID: 31469802
Hielo is excellent at AJAX.
Your code and explanations make sense.
Thanks.
0
 
LVL 82

Expert Comment

by:hielo
ID: 21848423
You are welcome!
0
 
LVL 5

Author Comment

by:Isaac
ID: 23185233
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:
http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_23986253.html

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
asp.net repeater js datatable 6 89
AJAX Slow 15 69
jquery not working after div reload 4 36
How to hide contact form only if no validation errors 4 28
Today I am discussing AJAX problems in IE7 and I bet this will helps many guys out here who have problems with AJAX work. Lets start with the discovery of problem and then we will talk about its different solutions. My last two projects included …
OverviewThis article demonstrates a simple search form using AJAX. The purpose of the article is to demonstrate how to use the same code to render a page and javascript (JQuery) and AJAX to make subsequent calls to refine the results. The princip…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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