Tag Archives: AJAX

Selenium – Element not found in the cache

You probably will come across the following error frequently when writing Selenium test case for a Ajax-rich website.

  • Error: Element not found in the cache – perhaps the page has changed since it was looked up

 

This is because the Selenium WebDriver reference to your element would now be stale as the DOM has been modified by Ajax. To resolve the problem in Java, you can make us of the WebDriverWait and find the element each time before you use it.
Continue reading Selenium – Element not found in the cache

Advertisements

Apache – Enable Cross-origin resource sharing CORS

Long time ago, we talked about using JSONP to tackle to cross domain ajax issue.
jQuery & JSON – Make Cross Domain Request Using jQuery.getJSON() with JSONP

But this requires server side coding. If you are allow to edit the Apache config, you can simply Enable the CORS (Cross-origin resource sharing) in the VirtualHost file as follow.

1. Enable the mod_headers in Apache by entering the following command in shell.

a2enmod headers

Continue reading Apache – Enable Cross-origin resource sharing CORS

Drupal 7 – Simple Ajax implementation @ 3

In the past 2 days we have developed a custom module which demonstrates the basic Ajax implementation in Drupal 7.

 

Today i will continue the example written by Kevin Hankens and make the module more secure. We want to add a token in the Ajax request such that the server could check if it comes from a valid user. This token could be obtained from drupal_get_token() which will return a fixed token value for each user session. Here are the list of changes in the new eureka_ajax.module.

  • Set the token value in Drupal.settings in hook_init()
  • Add the token as query string in the theme_ajax_link()
  • Check if the token is valid in ajax_request_callback()

Continue reading Drupal 7 – Simple Ajax implementation @ 3

Drupal 7 – Simple Ajax implementation @ 2

I will continue the Ajax example which we did in
Drupal 7 – Simple Ajax implementation @ 1

So this time we will add some access control on the above example. In Drupal 7 & 8 development, we could create new permissions by implementing the hook_permission(). After that we could modify the access arguments in the hook_menu().
Continue reading Drupal 7 – Simple Ajax implementation @ 2

Drupal 7 – Simple Ajax implementation @ 1

In this post, i will show you how to implement a simple Ajax function in Drupal 7. The following example code is based on the blog post written by Kevin Hankens about implementing Ajax in Drupal 6.
Kevin Hankens’s blog – Drupal, jQuery and $.ajax() easyness

What i am going to do is the same as Kevin’s example. But for simplicity, i removed the access control logic so all content is visible to anonymous users.
Continue reading Drupal 7 – Simple Ajax implementation @ 1

Drupal 7 – Reference field option limit for hierarchy taxonomy

Update @ 2013-11-28: You can also consider using Taxonomy Term Reference Tree Widget suggested by kenorb. =D

When you have a hierarchy structure of taxonomy, the default selection list is not quite user friendly because it list out all the parent and child terms. Assume with want to attach a country and city terms to the Article content type. The most straight forward way is create one vocabulary with some countries as parent terms and some cities as child terms like the following list.
  — England
    — London
    — Manchester
  — France
    — Lyon
    — Paris

It turns on that when someone is adding a new article, he may select either a country term or a city term. That is probably not what we want.
Continue reading Drupal 7 – Reference field option limit for hierarchy taxonomy

Rails – Simple Ajax Create Form

Rails provides a very easy way to implement Ajax. I got a Service and a ServiceComment models and each service has many service_comments. I have a service_comment create form and a partial which shows all the service_comments of that viewing service in the app/views/services/show.html.erb. Everything works fine without Ajax. Now comes to the Rails magic. Continue reading Rails – Simple Ajax Create Form

Ajax implementation on CakePHP @ 3

Recently i have started another CakePHP project. i found that the example in Ajax implementation on CakePHP @ 2 should be changed as follow.

ajax_controller.php

<?php
Class AjaxController extends AppController {
	var $name = 'Ajax';
	var $helpers = array('Form','Html','Javascript', 'Ajax');
	var $components = array('RequestHandler');

	function afterAjaxAction () {
		// get the $this->data to collect the form information
		// save the object to database
		// render the after_ajax_call.ctp
		$this->render('/elements/layout/after_ajax_call');
	}
}

Continue reading Ajax implementation on CakePHP @ 3