Utherr12 Posted November 29, 2010 Share Posted November 29, 2010 I want to start by saying that I'm a complete noob at AJAX, i know what's it for what it does and how it works, but i never experienced anything with it and practically I don't know how "to do" it.http://pastebin.ca/2005628 <-- JS codehttp://pastebin.ca/2005610 <-- PHP codeThere's no error... just that when i press the Modify Button, it doesn't do anything.You can try this here: http://89.115.144.183/blogger/index.php?postID=9 Link to comment Share on other sites More sharing options...
Ingolme Posted November 29, 2010 Share Posted November 29, 2010 This line isn't doing anything. document.getElementById('replace') = ... You probably meant to modify the innerHTML: document.getElementById('replace').innerHTML = ... Link to comment Share on other sites More sharing options...
Utherr12 Posted November 29, 2010 Author Share Posted November 29, 2010 Oops my bad, i updated the pastebin: http://pastebin.ca/2005628 it still doesn't work. Link to comment Share on other sites More sharing options...
Ingolme Posted November 29, 2010 Share Posted November 29, 2010 Why are you checking for a readystate before sending the request? if((Ajax.readyState==4)||(Ajax.readystate==0)) { var Content = document.getElementById('comm').innerHTML; var Cid = document.getElementById('cid').value; Ajax.open("POST","editComm.php?cid="+Cid, true); Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); Ajax.send("content="+Content);} readyState won't ever be 4 before the request is sent, and you haven't sent it.And readyState might have been 0, but you were comparing readystate instead of readyState.And finally, it would be preferrable to set the onreadystatechange handler before sending the request. Link to comment Share on other sites More sharing options...
Utherr12 Posted November 29, 2010 Author Share Posted November 29, 2010 Ok, now the AJAX code works but it doesn't change anything.I have the POST in log : "POST /blogger/editComm.php?cid=6 HTTP/1.1" 200 296 "http://89.115.144.183/blogger/index.php?postID=9" function sendAjax(){ Ajax = newAjax(); if((Ajax.readyState==4)||(Ajax.readyState==0)) { var Content = document.getElementById('comm').innerHTML; var Cid = document.getElementById('cid').value; Ajax.open("POST","editComm.php?cid="+Cid, true); Ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); Ajax.onreadystatechange = function() { if(Ajax.readyState==4) { content_response = Ajax.responseText; document.getElementById('replace').innerHTML = "<p id=\"content\" class=\"body\">"+content_response+"</p><a style=\"font-size:x-small\" href=\"java script:addCom()\">[Modify]</a>"; } } Ajax.send("content="+Content); }} Even after the refresh the comments is still the same, it's like the php script didn't do anything. Link to comment Share on other sites More sharing options...
Ingolme Posted November 29, 2010 Share Posted November 29, 2010 Have you checked to see if you're receiving anything from the server?Just alert(Ajax.responseText) to see if it has anything. Link to comment Share on other sites More sharing options...
Utherr12 Posted November 29, 2010 Author Share Posted November 29, 2010 The value of Ajax.responseText is "Test" (it's unchanged) Link to comment Share on other sites More sharing options...
Ingolme Posted November 29, 2010 Share Posted November 29, 2010 So, you know you're receiving a response from the server. That means that the problem is putting the response in the page. I'll examine that line: document.getElementById('replace').innerHTML = "<p id=\"content\" class=\"body\">"+content_response+"</p><a style=\"font-size:x-small\" href=\"java script:addCom()\">[Modify]</a>"; At the moment I don't see anything wrong with it.The "replace" element should have "Test" in it and a little [Modify] link next to it. Link to comment Share on other sites More sharing options...
Utherr12 Posted November 29, 2010 Author Share Posted November 29, 2010 Oh, thanks a lot dude, you're most helpful.I'm going to college right now, then for a brief moment i can check the forums, but I can't stay long cuz i'm having a long partying night ahead. Link to comment Share on other sites More sharing options...
Utherr12 Posted December 1, 2010 Author Share Posted December 1, 2010 I found out why the 'content' is not being modified, its because when I press [Modifiy] the js replaces some code in there and puts a textarea of id='comm' ... change which doesn't appear in the page source (or it appears but you can't see it unless you do a "view selection source" and see that the textarea is invoked with the last content the comment had).How do I get around this?You can see for yourself: http://89.115.144.183/blogger/index.php?postID=9 post a comment then try to edit it. After pressing [modify] go check the whole source of the page...there's no textarea. If you view selection source (of that textarea) you could see that it exists with the previous innerHTML as the comment had. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.