Jump to content

bmx322

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

bmx322's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi All! I'm trying to populate an array with the results of the the request. I keep getting the error catch "Response failed". I want to send 5 requests and fill the array after each request. The database code works, I tested it in the database(MySQL) and I get a result there. It just doesn't seem to want to populate the array on each iteration. I had a different setup that output the results but it was buggy, so I thought I'd populate an array so I don't have the delay of sending a request each time I want to populate the DIV. Any thoughts would be greatly appreciated. Here's the AJAX code. Then the PHP code. <SCRIPT language=JavaScript type="text/javascript"> var http = createRequestObject(); var i = 1; //global var var scripts = new Array(); // blobal array to hold the responses from the requests function createRequestObject() { // find the correct xmlHTTP, works with IE, FF and Opera var xmlhttp; try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { xmlhttp=null; } } if(!xmlhttp&&typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } return xmlhttp; } // Make the XMLHttpRequest object function sendRequest() { // Open PHP script for requests try{ var page = "testimo_query.php?num=" + i; http.open("GET", page, true); http.setRequestHeader('Content-Type', "text/text"); http.onreadystatechange = setArray; http.send(null); } catch(e){ // caught an error alert('Request send failed.'); } } function setArray(){ try{ if(http.readyState == 4){ scripts[i] = http.responseText; i++; if (i<6){ sendRequest(); }else { handleresponse();} } } catch(e){ // caught an error alert('Response failed.'); } } function handleResponse() { for(j=1; j<6;j++){ var response = scripts[j]; Effect.Appear('ajaxDiv', { duration: 1.0 }); // UPDATE ajaxTest content document.getElementById("ajaxDiv").innerHTML = response; setTimeout(Effect.Fade('ajaxDiv', { duration: 1.0 }),5000); } } window.onload=function() { sendRequest(); } </script> PHP code <?php include("inc_openConnection.php"); $rec = $_GET['num']; //used to grab specific record $rec= $rec-1; // want to start with record ZERO $start = 1; // this is the limit of returned query records $sql = "select fName, lName,date,state,country,testimonial from testimonials where approved = 1 order by t_id desc limit $rec,$start"; $rs = mysql_query($sql); $row = mysql_fetch_array($rs); $fn = $row['fName']; $ln = $row['lName']; $date = $row['date']; $state = $row['state']; $c = $row['country']; $t = $row['testimonial']; $response = "<font color='blue'><p>"; $response .= "\""; $response .= $t; $response .= "\"</p></font><font size='1'>"; $response .= $fn; $response .= " "; $response .= $ln; $response .= "<br />"; $response .= $state; $response .= ","; $response .= $c; $response .= "<br />"; $response .= $date; $response .= "<br /></font><br /><font size=1 align='right'><a href='testimonials.php'>See more...</a></font></p>"; echo "$response"; ?>
  2. Hello All You Brilliant Folk! First, thanks to all those who helped me get my ajax fixed! Now that I have a div that is gets different fesh content every 10 seconds from the database I would like to have it fade in and out. I come here as a last resort. I like to try and figure things out. I got the ajax script almost working and only had ONE error that I couldn't find. Just so you know I don't come here asking you all to write my code! Well, again, after hours of searching, reading, and trying to find a good example of the fade thingy, I've come here. I'm using PHP, AJAX, and MySQL for this. It is not using JQuery, don't know if that will help. Here's the process flow.The ajax populates a div on page load and refreshes the content every 10 seconds (at this point). I'd like the content to fade out, grab the next content, then fade in with the new content. Here's the working code minus the PHP file. ALL HELP IS GREATLY APPRECIATED! <html> <head> <SCRIPT language=JavaScript type="text/javascript"> var http = createRequestObject(); var i = 1; function createRequestObject() { // find the correct xmlHTTP, works with IE, FF and Opera var xmlhttp; try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { xmlhttp=null; } } if(!xmlhttp&&typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } return xmlhttp; } // Make the XMLHttpRequest object function sendRequest() { // Open PHP script for requests try{ var page = "testimo_query.php?num=" + i; http.open("GET", page, true); http.setRequestHeader('Content-Type', "text/text"); http.onreadystatechange = handleResponse; http.send(null); } catch(e){ // caught an error alert('Request send failed.'); } if (i<6){ if(i==5){ i=1; }else{ i++; } } } function handleResponse() { try{ if(http.readyState == 4){ var response = http.responseText; // UPDATE ajaxTest content } } catch(e){ // caught an error alert('Response failed.'); } } function repeatloop() { sendRequest(); setTimeout("repeatloop()", 10000); } window.onload=function() { repeatloop(); } </script> </head> <body> <div id="ajaxDiv"> </div> </body> </html>
  3. And may I say! Thank you!! Thank you!! Thank you!! I took out the part you mentioned and all is well. As for the "Limit 1" and rewriting the $response; That was intentional during testing. I am going to expand the code to get a different record each time. Again! Thank you!!
  4. IE 8 and FF just shows "undefined" as the only output. It seems I'm not getting any data back from the database but I'm real good with PHP and SQL, I double checked that, it seems fine. All I really did was imitate what was on the tutorials and examples as far as the PHP page is concerned. Thanks for responding.
  5. Hello! I'm new to ajax but have been programming for over 6 years with PHP. The issue I am having is: I get "undefined" as the only output from my test scripts. I have two files: test.html and testimo_query.php. I've been at this for 5 hours now. I've looked at a multitude of examples and did a couple tutorial, yet I can't seem to get any data. What is wrong (not with me silly- the code LOL) Thanks to all who take the time to help! Here are the two files. test.html <html> <head> <SCRIPT language=JavaScript type="text/javascript"> var http = createRequestObject(); function createRequestObject() { // find the correct xmlHTTP, works with IE, FF and Opera var xmlhttp; try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { xmlhttp=null; } } if(!xmlhttp&&typeof XMLHttpRequest!="undefined") { xmlhttp=new XMLHttpRequest(); } return xmlhttp; } // Make the XMLHttpRequest object function sendRequest() { // Open PHP script for requests try{ http.open("GET", "testimo_query.php", true); http.setRequestHeader('Content-Type', "text/text"); http.onreadystatechange = handleResponse; http.send(null); } catch(e){ // caught an error alert('Request send failed.'); } } function handleResponse() { try{ if(http.readyState == 4){ var response = http.responseText.documentElement; // UPDATE ajaxTest content document.getElementById("ajaxDiv").innerHTML = response; } } catch(e){ // caught an error alert('Response failed.'); } } function repeatloop() { sendRequest(); setTimeout("repeatloop()", 10000); } window.onload=function() { repeatloop(); } </script> </head> <body> <div id='ajaxDiv'></div> </body> </html> testimo_query.php <?php include("dbconnect.php"); $sql = "select q2b,q2a from 'TABLE NAME HERE' order by id_client desc limit 1"; $rs = mysql_query($sql); while($row = mysql_fetch_array($rs)){ $fn = $row['q2b']; $ln = $row['q2a']; $response = "$fn <br />"; $response .= "$ln"; $response .= "inside TESTIMO"; } echo $response; ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.