Call Jquery and ajax between two different domain (cross-domain)

Hi

If You have to call one page index.htmlfrom http://domain1.com to http://domain2.com
then You have to add code given below in top of index.html file of http://domain1.com in the top

switch ($_SERVER['HTTP_ORIGIN']) {
case 'http://domain1.com': case 'https://domain1.com':
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type');
break;
}

and call jquery or ajax in page of http://domain2.com.

It will be allow to access to access via ajax/jquery cross domain.

thanks.

Advertisements

Apply GROUP_CONCAT and CONCAT on a integer type value

Hi,

As we know GROUP_CONCAT returns a string result with the concatenated non-NULL values from a group and CONCAT Returns the string that results from concatenating the arguments.

If we apply these function on any not char type field then it will be return result something like [BLOG-3B] and something like this. So to apply on non chars field like int type we can use CONVERT mysql function for it.

For example

SELECT concat(CONVERT(column1,char(8))," , ") AS id,group_concat(CONVERT(column2, CHAR(20)) separator '|') AS result FROM `tablename` WHERE 1 group by column1

Here CONVERT will convert value of field column1 into a char type. and CONVERT function will be work on it.

thanks.

Sql Query for getting total number of empty fields in a row…

We can get total number of empty fields in a row in a table…


select SUM((`field1` = '') + (`field2` IS NULL) + ( `field3` = 0) + ...... (`fieldnth` = '')) from tablename where conditions;

Here we use
= ‘ ‘ for fields having field type string like varchar ,chars,text etc..
IS NULL is for field having default value NULL
= 0 is for field define integer type

cakephp pagination with search result

For make pagination compatible with search results

In controller file


<?php
if(isset($this-&gtrequest->data)) {
if (isset($this->request->data['User']['Search']) && ($this->request->data['User']['Search'] != '')) {
$search_keyword = $this->request->data['User']['Search'];
}
}
/*if search keyword is not enter then look for pagination condition params*/
elseif (!empty($this->request->params['named']['cond'])) {

$this->request->params['named']['cond'] = strtr($this->request->params['named']['cond'], '-_, ', '+/=');

$this->request->params['named']['cond'] = json_decode(base64_decode($this->request->params['named']['cond']), true);
if (isset($this->request->params['named']['cond']['search_keyword']) && $this->request->params['named']['cond']['gender'] != '') {
$search_keyword = trim($this->request->params['named']['cond']['search_keyword']);
}
}

if(!empty($search_keyword)){
$cond[] = "Product.productname LIKE '%" . $search_keyword . "'";
$separator['search_keyword'] = $search_keyword;
}

if (!empty($this->request->params)) {
if (isset($this->request->params["named"]["page"])) {
$urlSeparator[] = 'page:' . $this->request->params["named"]["page"];
}
if (isset($this->request->params["named"]["sort"])) {
$urlSeparator[] = 'sort:' . $this->request->params["named"]["sort"];
}
if (isset($this->request->params["named"]["direction"])) {
$urlSeparator[] = 'direction:' . $this->request->params["named"]["direction"];
}
}

$urlSeparator = implode("/", $urlSeparator);
$this->set('separator', $separator);
$this->set('urlSeparator', $urlSeparator);

$this->set('Products', $this->paginate("Product", $cond));

?>

and in ctp file


<?php

$this->Paginator->options(array('update' => '#div_id_for_update',
'url' => array('controller' => 'controller_name', 'action' => 'index', "cond" => strtr(base64_encode(json_encode($separator)), '+/=', '-_,')),
));

?>

Here in controller first we check if user click on search button then check for $this->request->data and set varriable $search_keywrd else check for pagiantion params and set $search_keyword and set pagination varriable and then in ctp file using $this->pagination->options set pagination link url with search condition.