Jump to content

BkJim

Members
  • Posts

    16
  • Joined

  • Last visited

Everything posted by BkJim

  1. Thank's DaveJ. That's what I was looking for. Thank's again.
  2. Hi every one,I am using textarea to insert data, but every time I press <ENTER> key, I get n on display and line doesn't change.Exp : Today. <ENTER> tomorrow.On display : Today.ntomorrow.I also try nl2br($_POST['article']) on PHP file and I get same result.How can I solve this ?Thank's in advance. index.htm article.js article.php
  3. Hi i have the same kind of requirement. I am not able to understand clearly what you are saying. up to adding an hidden iframe is ok. what do u meant by "submit the form normally to that iframe" ? do you mean to say submit the form through the iframe or something else. how can we submit the request to the iframe which is on the same page. can u provide some more explanation. if possible some sample code. It will be so much help full to me. Thanking you so much. Hi, I am looking for same explanation. Thank you so much.
  4. Hi every one,I am trying to upload text and image using getXMLHttpRequest, but I have no idea ofthe best way to process. Some help would be apreciated.Thank's. Html file JavaScript file PHP file
  5. I was trying this var message = "";xhr.send("id="+id+"&message="+message); And it worked. But your way is logical and BEST. I think everything is on control. Thank you so much JustSomeGuy for your time and patient.
  6. I know de point of this forum man and you probably right about GET but why it did work with no changing id ? Now, what about message on the next line. xhr.send("id="+id+"&message="+message); I guess it need some thing empty like this var message = ""; Ok I will let you know soon. Thanks.
  7. Ok, you right. But don't forget minichat.php is displaying on index.php so this is the line with error in minichat.php $response = mysql_query("SELECT * FROM message WHERE (user_id = '".$_POST['id']."')"); And error message ( ! ) Notice: Undefined index: id in C:wampwwwminichatminichat.php on line 14 Look, you have tables and all pages. Why don't you try to see what is going on ? That is all I have.
  8. Around line 14. Of course I am calling with user_id in WHILE loop.
  9. In index.php <?phpwhile ($data = mysql_fetch_array($req_mem)) { echo '<div id="refdiv'.$data['user_id'].'" style="height: 100px; width: 200px; overflow: auto; background-color: #CCCCCC; border: 1px solid #555555;"></div> <input type="text" id="message'.$data['user_id'].'" style="width: 200px;" /> <input type="button" value="Envoyer" onclick="submitChat('.$data['user_id'].');" /><script type="text/javascript">setInterval("refreshChat('' . $data['user_id'] . '')", 2000);</script>';}?> And error message ( ! ) Notice: Undefined index: id in C:wampwwwminichatindex.php on line 14
  10. That is what I did. Inside the WHILE.
  11. Error message. Notice : Undefined index. It doesn't walk.
  12. Yes I know but every thing is Ok when div ID is not variable. When div ID is variable, nothing walks any more.
  13. Ok I am trying this function refreshChat(id){ var xhr = getXMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) { document.getElementById('rafdiv'+id).innerHTML = xhr.responseText; // Données textuelles récupérées } }; xhr.open("GET", "minichat.php", true); xhr.send(null);}var mytimer = setInterval(function() {refreshChat(id)}, 2000); But it doesn't walk at all.
  14. Thanks, But the problem is that Ajax doesn't understand English that way. I try setInterval but it doesn't walk with changing ID. I would appreciate if some one else can help.
  15. I am printing the hole page of minichat.php on index.php with div. <div id="refdiv'.$data['user_id'].'" style="height: 100px; width: 200px; overflow: auto; background-color: #CCCCCC; border: 1px solid #555555;"></div> inside WHILE. That is the raison why I am asking for refresh. How to do that, you have my code.
  16. Hi every one, 1 - My database (minichat) has 2 tables CREATE TABLE IF NOT EXISTS `user` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `user_name` varchar(64) DEFAULT NULL, PRIMARY KEY (`user_id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ; INSERT INTO user (user_id, user_name) VALUES ('', 'John');INSERT INTO user (user_id, user_name) VALUES ('', 'Mark');INSERT INTO user (user_id, user_name) VALUES ('', 'Peter');INSERT INTO user (user_id, user_name) VALUES ('', 'Simon'); CREATE TABLE IF NOT EXISTS `message` ( `id` int(11) NOT NULL AUTO_INCREMENT, `my_id` int(6) NOT NULL, `user_id` int(6) NOT NULL, `message` varchar(255) NOT NULL, `timestamp` int(255) NOT NULL, PRIMARY KEY (`id`)) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=14 ; 2 - My application has 3 pages index.php <?php$connexion = mysql_connect ("localhost", "root", "") or die (mysql_error ());$base = mysql_select_db ("minichat") or die (mysql_error ());$req_mem = mysql_query('SELECT * FROM user WHERE user_id <> 1 ORDER BY user_id DESC');?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><meta http-equiv="Content-Language" content="fr" /><title>Mini-Chat</title><script type="text/javascript" src="minichat.js"></script></head><body><h1>Mini-Chat</h1><?phpwhile ($data = mysql_fetch_array($req_mem)) { echo '<div id="refdiv'.$data['user_id'].'" style="height: 100px; width: 200px; overflow: auto; background-color: #CCCCCC; border: 1px solid #555555;"></div> <input type="text" id="message'.$data['user_id'].'" style="width: 200px;" /> <input type="button" value="Envoyer" onclick="submitChat('.$data['user_id'].');" />';}?></body></html> minichat.js function getXMLHttpRequest() { var xhr = null; if (window.XMLHttpRequest || window.ActiveXObject) { if (window.ActiveXObject) { try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); } } else { xhr = new XMLHttpRequest(); } } else { alert("XMLHTTPRequest..."); return null; } return xhr;}function submitChat(id){ var xhr = getXMLHttpRequest(); var message = encodeURIComponent(document.getElementById('message'+id).value); document.getElementById('message'+id).value = ""; xhr.onreadystatechange = function() { if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) { document.getElementById('refdiv'+id).innerHTML = xhr.responseText; } }; xhr.open("POST", "minichat.php", true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send("id="+id+"&message="+message);} minichat.php <?phpheader("Content-Type: text/html; charset=iso-8859-1");mysql_connect("localhost", "root", "");mysql_select_db("minichat");if (isset($_POST['message'])) { if (!empty($_POST['message'])) { $message = mysql_real_escape_string(utf8_decode($_POST['message'])); mysql_query("INSERT INTO message(my_id, user_id, message , timestamp) VALUES(1, '".$_POST['id']."', '$message', '".time()."')"); }}$response = mysql_query("SELECT * FROM message WHERE (user_id = '".$_POST['id']."')");while($val = mysql_fetch_array($response)){ echo '<p><strong">'.htmlentities(stripslashes($val['user_id'])).'</strong> à '.date('H:i:s',$val['timestamp']).' : '. htmlentities(stripslashes($val['message'])) .'</p>';}mysql_close();?> 3 - My question Can you please tell me how to refresh refdiv in WHILE ('refdiv'+id) every 2 seconds (2000 milliseconds)Because I need unique div associate with user_id. Thank you in advance.
×
×
  • Create New...