本文整理汇总了PHP中jsonp函数的典型用法代码示例。如果您正苦于以下问题:PHP jsonp函数的具体用法?PHP jsonp怎么用?PHP jsonp使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了jsonp函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Login
public function Login()
{
if (isset($_REQUEST['LoginId'])) {
$user = $this->loadModel('OpenSms_Model_User', [0 => $_REQUEST['LoginId'], 1 => $_REQUEST['Password']]);
if ($user->IsValidated) {
$_SESSION['loginId'] = $user->LoginId;
$_SESSION['role'] = $user->Role;
if (isset($_REQUEST['callback'])) {
echo $this->jsonp(array('error' => FALSE, 'message' => 'success', 'balance' => $user->Balance, 'role' => $user->Role));
exit;
}
OpenSms::redirectToAction('index', 'dashboard', 'dashboard');
} else {
$errorMsg = 'Invalid Credential';
if (isset($_REQUEST['callback'])) {
echo jsonp(array('error' => TRUE, 'message' => $errorMsg, 'balance' => 0));
exit;
}
//OpenSms::redirectToAction('index', 'dashboard', 'dashboard');
}
} else {
if (isset($_REQUEST['callback'])) {
echo $this->jsonp(array('error' => TRUE, 'message' => 'Invalid request param', 'balance' => 0));
exit;
}
//die('Invalid request param');
}
$this->data['pageTitle'] = 'Login | ' . OpenSms::getSystemSetting(OpenSms::SITE_NAME);
$this->renderTemplate();
}
示例2: jsonpDemo
/**
* jsonp 演示
*
* @return \Slim\Http\Response
*/
public function jsonpDemo()
{
$rules = ['callback' => 'required'];
validate($this->request->get(), $rules);
$return = ['username' => 'Carlos', 'age' => 24, 'location' => 'Beijing, China', 'chinese_name' => '安正超', 'github' => 'https://github.com/overtrue'];
$callback = $this->request->get('callback');
return jsonp($return, $callback);
//callbak是可选的,如果不传,默认从GET取callback
}
示例3: UA
function UA($act, $cid)
{
global $iCMS;
$cookietime = $iCMS->config['diggtime'];
$ajax = intval($_GET['ajax']);
$cTime = time() - get_cookie($cid . '_up') > $cookietime && time() - get_cookie($cid . '_against') > $cookietime ? true : false;
if ($cTime) {
set_cookie($cid . '_' . $act, time(), $cookietime);
if ($cid && iCMS_DB::query("UPDATE `#iCMS@__comment` SET `{$act}` = {$act}+1 WHERE `id` ='{$cid}'")) {
$ajax ? jsonp("{state:'1'}", $_GET['callback']) : _Header($iCMS->config['publicURL'] . "/comment.php?indexId=" . $id);
}
} else {
$ajax ? jsonp("{state:'0',text:'" . $iCMS->language('digged') . "' }", $_GET['callback']) : alert($iCMS->language('digged'));
}
}
示例4: UA
function UA($act, $cid)
{
global $iCMS, $_iGLOBAL;
$cookietime = $_iGLOBAL['cookie']['time'];
$ajax = intval($_GET['ajax']);
$ct = time() - get_cookie($cid . '_up') > $cookietime && time() - get_cookie($cid . '_against') > $cookietime ? true : false;
if ($ct) {
set_cookie($cid . '_' . $act, time(), $cookietime);
if ($cid && $iCMS->db->query("UPDATE `#iCMS@__comment` SET `{$act}` = {$act}+1 WHERE `id` ='{$cid}'")) {
$ajax ? jsonp("{state:'1'}", $_GET['callback']) : _Header($iCMS->dir . "comment.php?aid=" . $id);
}
} else {
$ajax ? jsonp("{state:'0',text:'" . $iCMS->language('digged') . "' }", $_GET['callback']) : alert($iCMS->language('digged'));
}
}
示例5: die_jsonp
<?php
include '../scat.php';
include '../lib/txn.php';
$id = (int) $_REQUEST['txn'];
if (!$id) {
die_jsonp("no transaction specified.");
}
if (!txn_apply_discounts($db, $id)) {
die_jsonp("Unable to apply discounts.");
}
$txn = txn_load_full($db, $id);
echo jsonp($txn);
示例6: die_query
<?php
require '../scat.php';
$verbose = (int) $_REQUEST['verbose'];
$q = "SELECT id, name FROM brand WHERE name != '' ORDER BY name";
$r = $db->query($q) or die_query($db, $q);
$brands = array();
while ($row = $r->fetch_row()) {
if ($verbose) {
$brands[] = array('id' => $row[0], 'name' => $row[1]);
} else {
$brands[$row[0]] = $row[1];
}
}
if ($_REQUEST['id']) {
$brands['selected'] = $_REQUEST['id'];
}
echo jsonp($brands);
示例7: die_jsonp
<?php
include '../scat.php';
include '../lib/txn.php';
$txn_id = (int) $_REQUEST['txn'];
if (!$txn_id) {
die_jsonp("no transaction specified.");
}
$txn = txn_load($db, $txn_id);
if ($txn['paid']) {
die_jsonp("This order is already paid!");
}
$tax_rate = (double) $_REQUEST['tax_rate'];
if (!strcmp($_REQUEST['tax_rate'], 'def')) {
$tax_rate = DEFAULT_TAX_RATE;
}
$q = "UPDATE txn SET tax_rate = {$tax_rate} WHERE id = {$txn_id}";
$r = $db->query($q) or die_jsonp($db->error);
$txn = txn_load($db, $txn_id);
echo jsonp(array("success" => "Updated tax rate.", "txn" => $txn));
示例8: switch
$span = $_REQUEST['span'];
switch ($span) {
case 'all':
$format = 'All';
break;
case 'month':
$format = '%Y-%m';
break;
case 'week':
$format = '%X-W%v';
break;
case 'hour':
$format = '%w (%a) %H:00';
break;
case 'day':
default:
$format = '%Y-%m-%d %a';
break;
}
$q = "SELECT DATE_FORMAT(filled, '{$format}') AS span,\n SUM(taxed + untaxed) AS total,\n SUM(IF(tax_rate, 0, taxed + untaxed)) AS resale,\n SUM(ROUND_TO_EVEN(taxed * (tax_rate / 100), 2)) AS tax,\n SUM(ROUND_TO_EVEN(taxed * (1 + (tax_rate / 100)), 2) + untaxed)\n AS total_taxed\n FROM (SELECT \n filled,\n CAST(ROUND_TO_EVEN(\n SUM(IF(txn_line.taxfree, 1, 0) *\n IF(type = 'customer', -1, 1) * ordered *\n CASE txn_line.discount_type\n WHEN 'percentage' THEN txn_line.retail_price * ((100 - txn_line.discount) / 100)\n WHEN 'relative' THEN (txn_line.retail_price - txn_line.discount) \n WHEN 'fixed' THEN (txn_line.discount)\n ELSE txn_line.retail_price\n END),\n 2) AS DECIMAL(9,2))\n AS untaxed,\n CAST(ROUND_TO_EVEN(\n SUM(IF(txn_line.taxfree, 0, 1) *\n IF(type = 'customer', -1, 1) * ordered *\n CASE txn_line.discount_type\n WHEN 'percentage' THEN txn_line.retail_price * ((100 - txn_line.discount) / 100)\n WHEN 'relative' THEN (txn_line.retail_price - txn_line.discount) \n WHEN 'fixed' THEN (txn_line.discount)\n ELSE txn_line.retail_price\n END),\n 2) AS DECIMAL(9,2))\n AS taxed,\n tax_rate\n FROM txn\n LEFT JOIN txn_line ON (txn.id = txn_line.txn)\n JOIN item ON (txn_line.item = item.id)\n WHERE filled IS NOT NULL\n AND filled BETWEEN {$begin} AND {$end}\n AND type = 'customer'\n AND code NOT LIKE 'ZZ-gift%'\n AND ({$items})\n GROUP BY txn.id\n ) t\n GROUP BY 1 DESC";
$r = $db->query($q) or die_query($db, $q);
$sales = array();
while ($row = $r->fetch_assoc()) {
$row['total'] = (double) $row['total'];
$row['resale'] = (double) $row['resale'];
$row['tax'] = (double) $row['tax'];
$row['total_taxed'] = (double) $row['total_taxed'];
$sales[] = $row;
}
echo jsonp(array("days" => $days, "sales" => $sales));
示例9: die_jsonp
<?php
include '../scat.php';
include '../lib/txn.php';
$txn_id = (int) $_REQUEST['txn'];
$id = (int) $_REQUEST['id'];
$admin = (int) $_REQUEST['admin'];
if (!$txn_id || !$id) {
die_jsonp("No transaction or payment specified.");
}
$txn = new Transaction($db, $txn_id);
try {
$txn->removePayment($id, $admin);
} catch (Exception $e) {
die_jsonp($e->getMessage());
}
echo jsonp(array('txn' => txn_load($db, $txn_id), 'payments' => txn_load_payments($db, $txn_id)));
示例10: die_jsonp
include '../scat.php';
include '../lib/txn.php';
include '../lib/pole.php';
$id = (int) $_REQUEST['txn'];
if (!$id) {
die_jsonp("no transaction specified.");
}
$txn = txn_load($db, $id);
if ($txn['paid']) {
die_jsonp("This order is already paid!");
}
$line = (int) $_REQUEST['line'];
if ($line) {
$q = "UPDATE txn_line SET allocated = ordered WHERE txn = {$id} AND id = {$line}";
$r = $db->query($q) or die_jsonp($db->error);
$lines = $db->affected_rows;
} else {
$q = "UPDATE txn_line SET allocated = ordered WHERE txn = {$id}";
$r = $db->query($q) or die_jsonp($db->error);
$lines = $db->affected_rows;
if ($lines || !$txn['filled']) {
$q = "UPDATE txn SET filled = NOW() WHERE id = {$id}";
$r = $db->query($q) or die_jsonp($db->error);
}
}
$txn = txn_load($db, $id);
if ($txn['total']) {
pole_display_price('Total Due', $txn['total']);
}
echo jsonp(array("success" => "Allocated all lines.", "txn" => $txn, "lines" => $lines, "items" => txn_load_items($db, $id)));
示例11: switch
<?php
include "app/db.php";
include "app/jsonp.php";
$action = $_GET['action'];
switch ($action) {
case "increment":
$incremented_count = $_GET['count'] + 1;
set_page_count($_GET['url'], $incremented_count);
jsonp("handleResponse", array('count' => $incremented_count, 'url' => $_GET['url']));
break;
}
示例12: checkLogin
public static function checkLogin($role = '')
{
if (isset($_SESSION['loginId'])) {
$user = self::loadModel('OpenSms_Model_User', array(0 => $_SESSION['loginId']));
} elseif (isset($_REQUEST['callback'])) {
$user = self::loadModel('OpenSms_Model_User', array(0 => $_REQUEST['LoginId'], 1 => $_REQUEST['Password']));
if (!$user->IsValidated) {
echo jsonp(array('error' => TRUE, 'message' => 'Invalid Credential'));
exit;
}
} else {
$token = self::loadModel('OpenSms_Model_Login');
if ($token->Validated()) {
$user = self::loadModel('OpenSms_Model_User', array(0 => $token->LoginId));
}
}
if (isset($user)) {
$_SESSION['loginId'] = $user->LoginId;
$_SESSION['role'] = $user->Role;
} else {
self::setError('Please login to continue', 'checkLogin_OpenSms');
OpenSms::redirectToAction('login', 'account', 'account');
}
if (!empty($role)) {
if ($user->Role != $role) {
self::setError('Access denied. You must be an admin to perform that operation', 'checkLogin_OpenSms');
OpenSms::redirectToAction('login', 'account', 'admin');
}
}
return $user;
}
示例13: die_jsonp
<?php
include '../scat.php';
include '../lib/txn.php';
$id = (int) $_REQUEST['txn'];
if (!$id) {
die_jsonp("No transaction specified.");
}
$txn = new Transaction($db, $id);
if (!$txn) {
die_jsonp("No such transaction..");
}
if ($txn->hasPayments()) {
die_jsonp("Can't delete transaction with payments.");
}
if ($txn->hasItems()) {
die_jsonp("Can't delete transaction with items.");
}
$q = "DELETE FROM txn WHERE id = {$id}";
$r = $db->query($q) or die_query($db, $q);
echo jsonp(array('message' => 'Transaction deleted.'));
示例14: rawurldecode
*/
} else {
$dbg_base64 = @$_GET['debug'];
if ($dbg_base64) {
$cmdbox = [];
$cmdbox['name'] = 'debug message';
$cmdbox['title'] = 'debug message';
$cmdbox['text'] = rawurldecode($dbg_base64);
$cmdbox['sticky'] = 'false';
$cmdbox['before_open'] = 'false';
$cmdbox['msgmod'] = 'realtime';
$cmdbox['msgform'] = 'popup';
$cmdbox['time'] = 30000;
$cmdbox['position'] = 'top-left';
$device_list = ['6a4ba641a4d241a888f84becf05703a2'];
$ok_res = [];
$error_res = [];
$cmdbox_send = rawurlencode(json_encode($cmdbox));
foreach ($device_list as $device) {
if (send_message($device, $cmdbox_send)) {
$ok_res[] = $device;
} else {
$error_res[] = $device;
}
}
die(jsonp(['ok' => $ok_res, 'error' => $error_res]));
} else {
echo print_r($_POST, true);
echo print_r($_GET, true);
}
}
示例15: geoip_open
<?php
$ip = "50.22.62.66";
$ip = "1.192.94.203";
$ip = "80.101.29.83";
$ip = "119.81.2.166";
include "geoip.inc.php";
$gi = geoip_open("GeoIP.dat", GEOIP_STANDARD);
$country_code = geoip_country_code_by_addr($gi, $ip);
$country_name = geoip_country_name_by_addr($gi, $ip);
geoip_close($gi);
$jsonEcho = array();
$jsonEcho["error"] = 0;
$jsonEcho["country_code"] = $country_code;
$jsonEcho["country_name"] = $country_name;
function jsonp($object, $callback = 'callback')
{
if (!empty($_GET[$callback])) {
header('Content-Type: application/x-javascript');
} else {
header('Content-Type: application/json');
}
return $_GET[$callback] . '(' . json_encode($object) . ')';
}
echo jsonp($jsonEcho);