本文整理汇总了PHP中ajax类的典型用法代码示例。如果您正苦于以下问题:PHP ajax类的具体用法?PHP ajax怎么用?PHP ajax使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ajax类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Render
public function Render($form = "", $response_location = "", $url = "", $args = "")
{
$errorMsg = '';
$errors = FALSE;
$Load = new Load();
if (function_exists('is_empty') == FALSE) {
// Load validate helper
$Load->Helper('validate');
}
if (is_empty($form) == FALSE) {
$this->form = $form;
}
if (is_empty($response_location) == FALSE) {
$this->response_location = $response_location;
}
if (is_empty($url) == FALSE) {
$this->url = $url;
}
if (is_empty($args) == FALSE) {
$this->args = $args;
}
if (is_empty($this->form)) {
$errorMsg .= ' form requerido :$obj-> Form("id-form")<br /> ';
$errors = TRUE;
}
if (is_empty($this->response_location)) {
$errorMsg .= ' response_location requerido : $obj-> ResponseLocation("id-div-location")<br /> ';
$errors = TRUE;
}
if (is_empty($this->url)) {
$errorMsg .= ' url requerida : $obj-> Url("Controller/Action")<br /> ';
$errors = TRUE;
}
if ($errors == TRUE) {
echo 'Error:<br />' . $errorMsg;
return FALSE;
} else {
// Crear respuesta
$butonsCode = $this->RenderButtons();
$params = 'form:' . $this->form . ';url:' . $this->url . ';args:' . $this->args . ';';
$fx = new ajax('submit', $this->response_location, $params);
$Result = ' <script type="text/javascript">
<!--
' . $butonsCode . '
$("#' . $this->form . '").validate({
submitHandler: function(form) {
' . $fx->render() . '
return false;
},invalidHandler: function(form, validator){
var errors = validator.numberOfInvalids();
if (errors) { alert("Por favor, llena los campos obligatorios");}
}
});
//-->
</script>';
return $Result;
}
}
示例2: action_files
public function action_files()
{
$files = array();
$limit = arr::get($_GET, 'limit', 10);
$offset = arr::get($_GET, 'offset', 0);
$query = ORM::factory('File');
if (arr::get($_GET, 'tags', false)) {
$tags = arr::get($_GET, 'tags');
if (arr::get($_GET, 'matchAll', false) == "true") {
$tagsquery = DB::select('files_tags.file_id')->from('files_tags')->where('files_tags.tag_id', 'IN', $tags)->group_by('files_tags.file_id')->having(DB::expr('COUNT(files_tags.file_id)'), '=', count($tags))->execute();
//die(var_dump($tagsquery));
} else {
$tagsquery = DB::select('files_tags.file_id')->distinct(true)->from('files_tags')->where('files_tags.tag_id', 'IN', $tags)->execute();
//die(var_dump($tagsquery));
}
if ((bool) $tagsquery->count()) {
$ids = array();
foreach ($tagsquery as $q) {
$ids[] = arr::get($q, 'file_id');
//$files[] = ORM::factory('File', arr::get($q, 'file_id'))->info();
}
$query = $query->where('id', 'IN', $ids);
} else {
// Empty resultset
ajax::success('ok', array('files' => array()));
}
}
$query = $query->order_by('created', 'DESC')->limit($limit)->offset($offset)->find_all();
if ((bool) $query->count()) {
foreach ($query as $file) {
$files[] = $file->info();
}
}
ajax::success('ok', array('files' => $files));
}
示例3: app_event_test_ajax1
function app_event_test_ajax1($page, $values)
{
global $config;
error_log("@app_event_test_ajax1 ==================");
error_log(print_r($values, true));
$a = array(array("caption" => "Test1", "value" => 90), array("caption" => "Test2", "value" => 91), array("caption" => "Test3", "value" => 92));
ajax::sendJSON($a);
}
示例4: loadRoute
public static function loadRoute()
{
$r = array('action' => 'default', 'values' => array(), 'method' => 'get', 'ajax' => false, 'view' => 'default');
if (isset($_SERVER['REQUEST_METHOD'])) {
$method = strtoupper($_SERVER['REQUEST_METHOD']);
} else {
$method = 'CLI';
}
if ($method == 'GET') {
$r['values'] = $_GET;
if (isset($_GET['_view'])) {
$r['view'] = $_GET['_view'];
}
} elseif ($method == 'POST') {
$r['values'] = $_POST;
$r['method'] = 'post';
if (isset($_POST['_view'])) {
$r['view'] = $_POST['_view'];
}
} elseif ($method == 'CLI') {
global $argv;
$r['method'] = 'cli';
$r['values'] = $argv;
}
$cfg_ajax_test = array(array('field' => 'ajax', 'data_type' => 'http', 'return_type' => 'any', 'action' => 'ajax'), array('field' => 'json', 'data_type' => 'http', 'return_type' => 'json', 'action' => 'json'), array('field' => 'jsonrpc', 'data_type' => 'jsonrpc', 'return_type' => 'json', 'action' => 'method'), array('field' => 'callback', 'data_type' => 'http', 'return_type' => 'jsonp', 'action' => 'method'), array('field' => 'jsonpCallback', 'data_type' => 'http', 'return_type' => 'jsonp', 'action' => 'method'));
$ajax_type = null;
if (isset($_REQUEST)) {
foreach ($cfg_ajax_test as $test) {
if (isset($_REQUEST[$test['field']])) {
$ajax_type = $test;
break;
}
}
}
if (!is_null($ajax_type)) {
$r['ajax'] = true;
$r['method'] = strtolower($method);
$r['action'] = strtolower($_REQUEST[$ajax_type['action']]);
$r['view'] = 'default';
if ($ajax_type['data_type'] == 'http') {
$r['values'] = $r['method'] == 'get' ? $_GET : $_POST;
} elseif ($ajax_type['data_type'] == 'jsonrpc') {
$r['values'] = json_decode(file_get_contents('php://input'));
$r['action'] = $r['values']['method'];
}
if ($ajax_type['return_type'] == 'json' || $ajax_type['return_type'] == 'jsonp') {
ajax::loadAJAX($r['values']);
ajax::setType($ajax_type['return_type']);
}
//error_log(print_r($ajax_type, true));
}
if (isset($r['values']['a'])) {
$r['action'] = strtolower($r['values']['a']);
}
return $r;
}
示例5: initialize
public function initialize()
{
$this->template = template::getInstance();
if ($this->ajax) {
$this->content = ajax::getInstance();
} else {
$this->content = index::getInstance();
}
$this->content->initialize();
}
示例6: ajax
function ajax()
{
global $user, $tenjin, $config_q;
if ($_GET["vote_for"] == 1) {
echo quote::vote_for(array("quote_id" => $_GET["q_id"], "user_id" => $user->data["user_id"], "ip" => $_SERVER['REMOTE_ADDR']));
} else {
if ($_GET["vote_against"] == 1) {
echo quote::vote_against(array("quote_id" => $_GET["q_id"], "user_id" => $user->data["user_id"], "ip" => $_SERVER['REMOTE_ADDR']));
/*
$cv = new vote(array(
"quote_id" => $_GET["q_id"],
"user_id" => $user->data["user_id"],
"ip" => $_SERVER['REMOTE_ADDR'],
));
$cv->vote_for();
*/
}
}
if ($_GET["get_quote_for_facebook"] == 1) {
echo ajax::get_quote_for_facebook($_GET["q_id"]);
}
if ($_GET["get_quotes_for_facebook"] == 1) {
quote::get_random_quotes_for_facebook();
die;
}
/* a strange kind of acl but ok
from here on you have to have permissions
*/
if (!can_access()) {
return true;
}
if ($_GET["dialog__add_quote"] == 1) {
$tenjin_template = $config_q["template_dir"] . '/dialog__add_quote.phtml';
$output = $tenjin->render($tenjin_template, $context);
echo $output;
} elseif ($_GET["get_tags"] == 1) {
/*$this->format_tags_as_links(array(
"tags" => $_POST["tags"],
));*/
} elseif ($_GET["format_tags_as_links"] == 1) {
$tag = new tag();
echo $tag->format_tags_as_links($_POST["tags"]);
} elseif ($_GET["set_tags"] == 1) {
$this->set_tags(array("tags" => $_POST["tags"], "q_id" => $_POST["q_id"]));
} elseif ($_GET["get_quote"] == 1) {
echo "get_quote";
} elseif ($_GET["set_quote"] == 1) {
echo "set_quote";
} elseif ($_GET["get_category"] == 1) {
$this->get_category(array("category_id" => $_POST["category_id"], "q_id" => $_POST["q_id"]));
} elseif ($_GET["set_category"] == 1) {
$this->set_category(array("category_id" => $_POST["category_id"], "q_id" => $_POST["q_id"]));
}
}
示例7: autocomplete
public function autocomplete()
{
$directories = array();
$path_prefix = Input::instance()->get("q");
foreach (glob("{$path_prefix}*") as $file) {
if (is_dir($file) && !is_link($file)) {
$directories[] = html::clean($file);
}
}
ajax::response(implode("\n", $directories));
}
示例8: action_get
public function action_get()
{
$visitors = ORM::factory('Visitor')->find_all();
$varray = array();
if ((bool) $visitors->count()) {
foreach ($visitors as $visitor) {
$varray[] = $visitor->info();
}
}
ajax::success('ok', array('visitors' => $varray));
}
示例9: autocomplete
public function autocomplete()
{
$tags = array();
$tag_parts = explode(",", Input::instance()->get("term"));
$tag_part = ltrim(end($tag_parts));
$tag_list = ORM::factory("tag")->where("name", "LIKE", Database::escape_for_like($tag_part) . "%")->order_by("name", "ASC")->limit(100)->find_all();
foreach ($tag_list as $tag) {
$tags[] = (string) html::clean($tag->name);
}
ajax::response(json_encode($tags));
}
示例10: action_get
public function action_get()
{
$errors = ORM::factory('Error')->order_by('time', 'DESC')->limit(10)->find_all();
$errs = array();
if ((bool) $errors->count()) {
foreach ($errors as $e) {
$errs[] = array('id' => $e->id, 'type' => $e->type, 'ip' => $e->ip, 'when' => date('d/m/Y H:i', $e->time), 'url' => $e->url);
}
}
ajax::success('', array('errors' => $errs));
}
示例11: autocomplete
public function autocomplete()
{
$directories = array();
$path_prefix = Input::instance()->get("term");
foreach (glob("{$path_prefix}*") as $file) {
if (is_dir($file) && !is_link($file)) {
$directories[] = (string) html::clean($file);
}
}
ajax::response(json_encode($directories));
}
示例12: action_get
public function action_get()
{
$content = ORM::factory('Content')->order_by('hits', 'DESC')->limit(10)->find_all();
$contents = array();
if ((bool) $content->count()) {
foreach ($content as $c) {
$contents[] = array('id' => $c->id, 'title' => $c->title, 'type' => $c->contenttype->display, 'hits' => $c->hits);
}
}
ajax::success('', array('contents' => $contents));
}
示例13: autocomplete
public function autocomplete()
{
$tags = array();
$tag_parts = explode(",", Input::instance()->get("q"));
$limit = Input::instance()->get("limit");
$tag_part = ltrim(end($tag_parts));
$tag_list = ORM::factory("tag")->where("name", "LIKE", "{$tag_part}%")->order_by("name", "ASC")->limit($limit)->find_all();
foreach ($tag_list as $tag) {
$tags[] = html::clean($tag->name);
}
ajax::response(implode("\n", $tags));
}
示例14: action_message
public function action_message()
{
$message = ORM::factory('Message', $this->request->param('id'));
if (!$message->loaded()) {
ajax::redirect('#/messages', __('The message wasn\'t found. Has it already been deleted?'));
}
$info = $message->info();
if ($message->read == 0) {
$message->set_read();
}
reply::ok(View::factory('Cms/Messages/message', array('message' => $message)), 'messages', array('viewModel' => 'viewModels/Messages/message', 'message' => $info));
}
示例15: BackendAjax
protected static function BackendAjax()
{
$sort = type::post('array', 'array');
$sql = sql::factory();
$sql->setTable('metainfos');
foreach ($sort as $s => $id) {
$sql->setWhere('id=' . $id);
$sql->addPost('sort', $s + 1);
$sql->update();
}
ajax::addReturn(message::success(lang::get('save_sorting'), true));
}