Page 1 of 1

Help with code please.

Posted: Fri Apr 27, 2007 9:24 am
by spamyboy
index.php

Code: Select all

<?php
require_once('connect.inc.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="JavaScript" src="motion.js"></script>
<script src="IDEGO%20_%20WITAMY_failai/prototype.js" type="text/javascript"></script>
<script type="text/javascript" src="IDEGO%20_%20WITAMY_failai/effects.js"></script>
<title>daily.lt</title>
<style type="text/css">
<!--
@import url("style.css");
-->
</style>
</head>
<body onload="javascript:getContent('content.php', 'content','');">
<script type="text/javascript" language="javascript">
   var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
      
      http_request.onreadystatechange = alertContents;
      http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
   }

   function alertContents() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById('myspan').innerHTML = result;            
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   
   function get(obj) {
      var poststr = "text=" + encodeURI( document.getElementById("text").value );
      makePOSTRequest('post.php', poststr);
   }
</script>

<script type="text/javascript" language="javascript">
function getContent(page, elementid, waitmsg){
var xmlhttp=false;
try {
    xmlhttp = new ActiveXObject('Msxml2.XMLHTTP'); 
    } catch (e) {
    try {
         xmlhttp = new ActiveXObject('Microsoft.XMLHTTP'); 
    } catch (E) {
         xmlhttp = false;
    }
 }
 if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
     xmlhttp = new XMLHttpRequest();
 }
xmlhttp.open('GET', page, true);    
xmlhttp.onreadystatechange=function() {
if(xmlhttp.readyState == 1){
document.getElementById(elementid).innerHTML = "<p><img src='images/waiting.gif' align='middle'> Please wait... <br />kazkas cia</p>" ;
   }else if(xmlhttp.readyState==4) { 
   var content = xmlhttp.responseText;
      if( content ){   
      document.getElementById(elementid).innerHTML = content;   
      }
   }
}
xmlhttp.send(null)
return;
}
</script>
<script type="text/javascript" language="Javascript">
function createXMLHttpRequest() {
var ua;
if(window.XMLHttpRequest) {
    try {
      ua = new XMLHttpRequest();
    } catch(e) {
      ua = false;
    }
  } else if(window.ActiveXObject) {
    try {
      ua = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
      ua = false;
    }
  }
  return ua;
}
var req = createXMLHttpRequest();
function sendRequest(id) {
  req.open('get', 'test.php?id=' + id);
  req.onreadystatechange = handleResponse;
  req.send(null);
}
function handleResponse() {
  if(req.readyState == 4){
    var response = req.responseText;
    var update = new Array();
    if(response.indexOf('||' != -1)) {
      update = response.split('||');
      document.getElementById(update[0]).innerHTML = update[1];
    }
  }
  else
  alert("loading" + ajax.readyState);
}
</script>
<div id="back">
<div id="nav" style="display:none; overflow:hidden; height:95px;"><form action="javascript:get(document.getElementById('form'));" name="form" id="form">
<textarea name="title" cols="50" rows="5" class="inputTextarea" id="title"></textarea>
<textarea name="text" cols="50" rows="5" class="inputTextarea" id="text"></textarea>
<input type="button" name="button" value="Submit" onclick="javascript:get(this.parentNode);javascript:getContent('content.php', 'content','');">
</form></div>
<div id="nav_open"><a href="javascript:;" onmousedown="toggleSlide('nav');">Open posting form</a></div>
<span name="myspan" id="myspan"></span>
<div id="content"></div>

<img src="IDEGO%20_%20WITAMY_failai/mini_onas.gif" alt="minimalizuj" onclick="return dofun1();" class="mouse">
<div style="" id="tresc1"><div style="" class="srodek1">
<img src="IDEGO%20_%20WITAMY_failai/tree_idego.gif" alt="idego - indywidualne (idealne) rozwi&#261;zania">
</div></div>
<script type="text/javascript">
// <![CDATA[
	$('tresc1').style.display = 'none';

	function dofun1()
	{
		new Effect.toggle($('tresc1'), 'slide');
		return false;
	}
// ]]>
</script>

</div>
</body>
</html>
content.php

Code: Select all

<?php
require_once('connect.inc.php');
$query = "SELECT * FROM daily ORDER BY id DESC";
$result = mysql_query($query) or die('Error, query failed');
while ($row = mysql_fetch_array($result)) {
echo '<div class="postinfo"><a href="javascript:sendRequest(\'' .$row['id']. '\');return dofun1();">' .$row['text']. '</a></div>
<div class="postcontent"><span id="showDiv' .$row['id']. '" class="postcontent"></span></div>
';
}
?>
In content.php, there is function

Code: Select all

return dofun1();
but it doesnt work BUT it does work in index.php

Code: Select all

<img src="IDEGO%20_%20WITAMY_failai/mini_onas.gif" alt="minimalizuj" onclick="return dofun1();" class="mouse">
, why ? could some one help to fix it... also if you have any sugessions on how to make code cleaner, pleas do.

Posted: Fri Apr 27, 2007 9:40 am
by jayshields
Please use more informative thread subjects, and please put an "e" on the end of "please", please.

Posted: Fri Apr 27, 2007 11:24 am
by spamyboy
The think is that same button that is in content.php as in index.php doesnt work.
Pleas help.

Posted: Fri Apr 27, 2007 11:48 am
by John Cartwright
You've been here long enough to know how to highlight your posts.. :evil:

Posted: Tue May 01, 2007 5:09 pm
by spamyboy
Bump.

Posted: Tue May 01, 2007 5:28 pm
by superdezign
You annoy me, and I don't even know you.
Post bumping? Seriously...

Anyway, explain what the problem is and maybe you'll get some help. I, personally, am not going to read through messy code to find an error.

Posted: Tue May 01, 2007 5:40 pm
by Ambush Commander
Why is the AJAX code in the <script> tag? I would presume prototype.js would have it already. Try removing it.