2014-04-03 59 views
0

我正在使用一個joomla模塊,我想修改它以自動加載默認的結果列表。當頁面加載時自動加載搜索結果

當前,當頁面加載沒有結果時顯示。如果所有搜索欄都爲空,並且用戶單擊搜索按鈕,頁面將加載所有數據。如果信息放在搜索字段中,結果將被分解以匹配輸入的內容。

我希望頁面在頁面加載時自動加載所有數據,而無需用戶單擊搜索。 我如何做到這一點?

我相信模塊使用Ajax,我相信,這會影響低於信息:

<?php 

    header('Access-Control-Allow-Origin: *'); 
    header('Content-Type: text/html'); 

    define('_JEXEC', 1); 
    define('DS', DIRECTORY_SEPARATOR); 

    ini_set("display_errors", "On"); 
    error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_WARNING); 

    $my_path = dirname(__FILE__); 
    $my_path = explode(DS.'modules',$my_path); 
    $my_path = $my_path[0];   

    if (file_exists($my_path . '/defines.php')) { 
     include_once $my_path . '/defines.php'; 
    } 

    if (!defined('_JDEFINES')) { 
     define('JPATH_BASE', $my_path); 
     require_once JPATH_BASE.'/includes/defines.php'; 
    } 

    require_once JPATH_BASE.'/includes/framework.php'; 
    $app = JFactory::getApplication('site'); 
    $app->initialise(); 

    /////////////////////////////////////////////////////////////////////////////////////////////// 

    $name = $_GET['name']; 
    $value = mb_strtolower($_GET['value']); 
    $next = mb_strtolower($_GET['next']); 

    $db = JFactory::getDBO(); 
    $query = "SELECT * FROM #__k2_extra_fields WHERE published = 1"; 

    $db->setQuery($query); 
    $results = $db->loadObjectList(); 

    $extra_val = ''; 
    $extra_id = 0; 
    foreach($results as $result) { 
     if(trim(mb_strtolower($result->name)) == trim($value) . " " . trim($next) || trim(mb_strtolower($result->name)) == trim($next) . " " . trim($value)) { 
      $extra_val = $result->value; 
      $extra_id = $result->id; 
      break; 
     } 
    } 

    require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_k2'.DS.'lib'.DS.'JSON.php'); 
    $json = new Services_JSON; 
    $extra_val = $json->decode($extra_val); 

    if($extra_val != '') { 
     foreach($extra_val as $val) { 
      echo "<option>" . $val->name . "</option>"; 
     } 
     echo "<option>".$extra_id."</option>"; 
    } 

?> 

請幫幫忙!

回答

0

嘗試使用這樣的事情

<html> 
<head> 
<script> 
function myFunction() 
{ 
alert("Page is loaded"); 
} 
</script> 
</head> 

<body onload="myFunction()"> 
<h1>Hello World!</h1> 
</body> 

</html> 

,那麼你可以很容易地改變myFunction的觸發你的點擊事件

<script> 
function myFunction() 
{ 
    document.getElementById('YOUR-BUTTON-ID').onclick(); 
} 
</script>