Posts Tagged with ajax

Displaying 1-5 of 5 results.
Wiki: How to make an AJAX call without jQuery with GET and POST?wiki
posted by admin on March 27, 2017
Using the following snippet you can do similar things pretty easily, like this:

ajax.get('/test.php', {foo: 'bar'}, function() {});

Here is the snippet:

var ajax = {};
ajax.x = function () {
if (typeof XMLHttpRequest !== 'undefined') {
return new XMLHttpRequest();
var versions = [

var xhr;
for (var i = 0; i < versions.length; i++) {
try {
xhr = new ActiveXObject(versions[i]);
} catch (e) {
return xhr;

ajax.send = function (url, callback, method, data, async) {
if (async === undefined) {
async = true;
var x = ajax.x();, url, async);
x.onreadystatechange = function () {
if (x.readyState == 4) {
if (method == 'POST') {
x.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');

ajax.get = function (url, data, callback, async) {
var query = [];
for (var key in data) {
query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
ajax.send(url + (query.length ? '?' + query.join('&') : ''), callback, 'GET', null, async)
}; = function (url, data, callback, async) {
var query = [];
for (var key in data) {
query.push(encodeURIComponent(key) + '=' + encodeURIComponent(data[key]));
ajax.send(url, callback, 'POST', query.join('&'), async)
Read more
Wiki: Yii 1.1 Minimizing Script Files by clientScript - scriptMap. CGoogleApi - initwiki
posted by admin on October 6, 2016
Complex pages often need to include many external JavaScript and CSS files. Because each file would cause one extra round trip to the server and back, we should minimize the number of script files by merging them into fewer ones. We should also consider reducing the size of each script file to reduce the network transmission time. There are many tools around to help on these two aspects.

For a page generated by Yii, chances are that some script files are rendered by components that we do not want to modify (e.g. Yii core components, third-party components). In order to minimizing these script files, we need two steps.

First, we declare the scripts to be minimized by configuring the scriptMap property of the clientScript application component. This can be done either in the application configuration or in code. For example,


What the above code does is that it maps those JavaScript files to the URL /js/all.js. If any of these JavaScript files need to be included by some components, Yii will include the URL (once) instead of the individual script files.

Second, we need to use some tools to merge (and perhaps compress) the JavaScript files into a single one and save it as js/all.js.

The same trick also applies to CSS files.

We can also improve page loading speed with the help of Google AJAX Libraries API. For example, we can include jquery.js from Google servers instead of our own server. To do so, we first configure the scriptMap as follows,


By mapping these script files to false, we prevent Yii from generating the code to include these files. Instead, we write the following code in our pages to explicitly include the script files from Google,

<?php echo CGoogleApi::init(); ?>

<?php echo CHtml::script(
CGoogleApi::load('jquery','1.3.2') . "\n" .
CGoogleApi::load('jquery.ajaxqueue.js') . "\n" .
); ?>
Read more
Resolved: Yii CGridView pagination not working and alert 500 or 404 error
posted by admin on April 23, 2016
I have trouble about cgridview pagination.
I am using admin page(/{module}/admin that) generated by gii.
it has search form and grid with pagination. its work well without urlmanager

but my team have create urlmanager rule long ago.




when I use admin page with this urlmanager rule. It has some problem.
- if not using grid sort or pagination. I can filter in grid and form.
- but if using sort or pagination. I can not filtering in grid and form anymore.

page link is wierd and i think because of some attribute(params) are null like this


if I am copy this url to another tab and Its can not filtering in grid and form too.
but if I remove attribute that has null value(BookManageMain%5Bbmm_code%5D//) I can filter grid and form.


console log (not sure filter use POST and sort/page use GET)

before click pagerlink or sorting

after click

Read more
Resolved: Yii 1.1: syntaxhighlighter extension CListView ajax pagination problem
posted by admin on December 25, 2015
CListView ajax pagination Can't find XML Brush etc.
First page working great, but when working ajax pagination, brushes not working, not finding any brushes.

My code:

<?php Yii::app()->syntaxhighlighter->addHighlighter(); ?>
Read more
Resolved: Syntaxhighlighter can't find any brushes after ajax request
posted by admin on December 25, 2015
After implementing pagination on my website, I was not able to highlight the code with SyntaxHighliter plugin. After AJAX call script was throwing an error: "Can't find brush for: BRUSH".Read more