1
xsell
Ajax in block
  • 2009/9/30 5:44

  • xsell

  • Quite a regular

  • Posts: 245

  • Since: 2008/9/2 1


hello
I made small Block with ajax Function , the goal of this block is to bring data from the sql equal to the sumbit word .

I made my module and tested the index . and all looks Good , so i made my block to show the same wht in the index .. the block shows no error but when tyep word it only say to wait.. and will never bring the equal data ..

this is my blok
<?php
function b_ajax_blocks_show() {
global  
$xoopsUser$xoopsConfig$xoopsDB$xoopsModuleConfig$xoopsOption;
$block = array();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
var http = createRequestObject();
function createRequestObject(){
    var request_;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        request_ = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
        request_ = new XMLHttpRequest();
    }
    return request_;
}
function getInfo(){
    http.open('get', 'ajax.php?word='+ document.form1.word.value);
    http.onreadystatechange = handleInfo;
    http.send(null);
}
function handleInfo(){
    if(http.readyState == 1){
        document.getElementById('mydiv').innerHTML = 'Wait.....';
    }
    if(http.readyState == 4){
        var response = http.responseText;
        document.getElementById('mydiv').innerHTML = response;
    }
}
</script>
 <?
$block
['content'] .= "'<center><table dir=rtl width=15% border=0>
<form name='form1' method='post' action=''>
     <input name='word' type='text' id='word' onkeyup='getInfo()' AUTOCOMPLETE='OFF'>
  </form>
</div>
<div align='center' id='mydiv'><font size='2' face='tahoma, arial'></font></div>
</form></table>
"
;
//$block['content']  =  "$content";
return $block;
}
?>

2
frankblack
Re: Ajax in block
  • 2009/9/30 6:42

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


You could use Firebug for debugging. I made something similar for debaser, with a jquery script called autocomplete. Works similar to Google Suggest.

Template:
<form name="ajaxsearcher" id="ajaxsearcher" action="javascript:void(null);" method="post">
<
div id="debsearchdiv">
<
span class="debsearchword"><{$smarty.const._MD_DEBASER_SEARCH}></span><input type="text" id="ajaxsearch" /> <img src="<{$smarty.const.DEBASER_IMG}>/dialog-ok.png" name="debsearchsubmit" style="float:left" id="debsearchsubmit" alt="<{$smarty.const._SUBMIT}>"  title="<{$smarty.const._SUBMIT}>" />
</
div>
</
form>
<
div id="searchresponse"></div>

<
script type="text/javascript" src="<{$xoops_url}>/modules/debaser/js/jquery.bgiframe.min.js"></script>
<
script type="text/javascript" src="<{$xoops_url}>/modules/debaser/js/jquery.ajaxQueue.js"></script>
<
script type="text/javascript" src="<{$xoops_url}>/modules/debaser/js/jquery.autocomplete.pack.js"></script>
<
script type="text/javascript">
$().
ready(function() {

    $(
"ajaxsearcher").attr({ autocomplete:"off" });
    
    function 
formatItem(row) {
        return 
row[0] + " (<strong>id: " row[1] + "</strong>)";
    }
    function 
formatResult(row) {
        return 
row[0].replace(/(<.+?>)/gi, '');
    }

    $("#ajaxsearch").autocomplete("debasersearch.php", {
        width: 260,
        selectFirst: false
    });

    $("#debsearchsubmit").click(function () {
        $("#searchresponse").load("<{$xoops_url}>/modules/debaser/ajaxed.php", { action : "ajaxsearch", searchitem1 : document.getElementById('ajaxsearch').value });
        });
    
});


</script>


debaser_search.php:
<?php
include 'header.php';

    if (isset(
$_GET['q']) && $_GET['q'] != '') {

        
$getquery addSlashes($_GET['q']);
        
$getlimit intval($_GET['limit']);

        
$result $xoopsDB->query("SELECT artist, title, genreid FROM ".$xoopsDB->prefix('debaser_files')." WHERE title LIKE '%$getquery%' OR artist LIKE '%$getquery%' OR album LIKE '%$getquery%' OR year LIKE '%$getquery%' OR year LIKE '%$getquery%' OR length LIKE '%$getquery%' OR frequence LIKE '%$getquery%' OR bitrate LIKE '%$getquery%' LIMIT $getlimit");

        while(list(
$artist$title$genreid) = $xoopsDB->fetchRow($result)) {
            if (
$gperm_handler->checkRight('DebaserCatPerm'$genreid$groups$module_id)) echo $artist." "."$titlen";
        }
    }

?>


ajaxed.php:
<?php
    
if (isset($_POST['action']) && $_POST['action'] == 'ajaxsearch') {

        
// check the values
        
$searchitem1 = isset($_POST['searchitem1']) ? addSlashes($_POST['searchitem1']) : '';

        
$result $xoopsDB->query("SELECT xfid, artist, title FROM ".$xoopsDB->prefix('debaser_files')." WHERE CONCAT_WS(' ', artist, title) LIKE '$searchitem1' OR artist LIKE '%$searchitem1%' OR title LIKE '%$searchitem1%'");

        
$returnresult '<br /><div id="debsearchresults"><h1>'._MD_DEBASER_SEARCHRES.'</h1>';

        while(list(
$getback$getback2$getback3) = $xoopsDB->fetchRow($result)) {
            
$returnresult .= '<span style="line-height:150%"<a href="'.DEBASER_URL.'/singlefile.php?id='.$getback.'">'.$getback2.' '.$getback3.'<br /></span>';
        }

        
$returnresult .= '</div>';
        echo 
$returnresult;
    }

?>


CSS:
/* autocomplete css */
.ac_results {
padding0px;
border1px solid black;
background-colorwhite;
overflowhidden;
z-index99999
}
.
ac_results ul {
width100%;
list-
style-positionoutside;
list-
stylenone;
padding0;
margin0
}
.
ac_results li {
margin0px;
padding2px 5px;
cursor: default;
displayblock;
fontmenu;
font-size12px;
line-height16px;
overflowhidden
}
.
ac_loading {
backgroundwhite url('../images/indicator.gif'right center no-repeat
}
.
ac_odd {
background-color#eee
}
.
ac_over {
background-color#231f20;
colorwhite
}

div#debsearchdiv {
padding2px;
background-color#231f20;
color#fff;
font-size12px;
height:24px
}

input#ajaxsearch {
height19px;
font-size12px;
width251px;
padding-top4px;
padding-left5px;
padding-right5px;
padding-bottom0px;
margin0px;
floatleft;
bordernone;
}
.
debsearchword {
float:left;
padding-right:5px;
padding-top:5px;
padding-left:5px;
font-weight:bold
}
div#debsearchresults {
padding10px;
background-color#231f20;
font-size12px
}
div#debsearchresults a {
colorsilver;
}
div#debsearchresults a:hover {
text-decorationunderline
}
div#debsearchresults h1 {
font-size18px;
font-weightbold;
color#fff;
margin-top0px
}


edit: this code might not work, because the textsanitizer killed backslashes used at some places, but I hope it shows you the way.

3
xsell
Re: Ajax in block
  • 2009/9/30 7:13

  • xsell

  • Quite a regular

  • Posts: 245

  • Since: 2008/9/2 1


Oh look Who is Here ..!!

To tell you the truth i been looking into debaser before you say that . :) i learned some from it .

The thing with my Block is that only micrsoft Explorer doese not comes up witht he result . Firefox , and Google Grhome have no Problem Come up with the result , So thats tells me Nothing wrong with The code .. do not know whts up with Poor old IE8.. Had to delete the Cash the Cookies , Temp .. then it Work.. Yah it DID ..

So seem was Temp and Cash Problem .. i do not mean XOOPS Cash by my PC..

4
frankblack
Re: Ajax in block
  • 2009/9/30 7:41

  • frankblack

  • Just can't stay away

  • Posts: 830

  • Since: 2005/6/13


Quote:
To tell you the truth i been looking into debaser before you say that . :) i learned some from it .


Cough! You must be joking! Learning how to do it NOT I assume.

Of course your code is much shorter/quicker than mine, but I am using jquery anyway so I don't care. Especially I like the eye candy that comes with some jquery scripts.

5
ghia
Re: Ajax in block
  • 2009/9/30 9:37

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Quote:
Had to delete the Cash the Cookies , Temp .. then it Worked
You mean Cache.
Cash is something to keep!

6
xsell
Re: Ajax in block
  • 2009/9/30 11:14

  • xsell

  • Quite a regular

  • Posts: 245

  • Since: 2008/9/2 1


Quote:
Cough! You must be joking! Learning how to do it NOT I assume.

I was Not Looking into Ajax or jquery in your Code but Needed Some info about the isadmin, isuser ..and Senak to the Report Link Code to use for my Own use . and Graped the html code from some of debaser template . Ha Sound Nothing left may as well Just take all .

Quote:
You mean Cache.
Cash is something to keep!


Ghia it Makes No different if you Do not have it .. :)

7
ghia
Re: Ajax in block
  • 2009/9/30 12:26

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1



Just preparing you for the event of!

Login

Who's Online

120 user(s) are online (61 user(s) are browsing Support Forums)


Members: 0


Guests: 120


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits