Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 页面加载时自动加载搜索结果_Javascript_Jquery_Ajax_Joomla3.0_Joomla K2 - Fatal编程技术网

Javascript 页面加载时自动加载搜索结果

Javascript 页面加载时自动加载搜索结果,javascript,jquery,ajax,joomla3.0,joomla-k2,Javascript,Jquery,Ajax,Joomla3.0,Joomla K2,我正在使用一个我想修改的joomla模块来自动加载默认结果列表 当前,当页面加载时,不会显示任何结果。如果所有搜索字段均为空且用户单击搜索按钮,则页面将加载所有数据。如果在搜索字段中放置了信息,则结果将被细分以匹配键入的内容 我希望页面在加载时自动加载所有数据,而无需用户单击搜索。 我如何做到这一点 我相信模块使用ajax,我相信影响这一点的信息如下: <?php header('Access-Control-Allow-Origin: *'); header('Con

我正在使用一个我想修改的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>";
    }

?>


请帮忙

试着用这样的东西

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

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

</html>

函数myFunction()
{
警报(“页面已加载”);
}
你好,世界!
然后,您可以轻松更改myFunction以触发单击事件时的搜索

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

函数myFunction()
{
document.getElementById('YOUR-BUTTON-ID').onclick();
}

要自动加载搜索结果,我们必须将搜索查询存储在会话变量中

这些链接将很好地描述如何在会话中管理请求变量,因此请求中没有变量,它将从会话中获取值