activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alikic <ali...@rogers.com>
Subject Re: Problem using Ajax to listen to a queue/topic
Date Wed, 29 Dec 2010 19:13:43 GMT

OK, mystery solved:)

I forgot to mentioned that I am *NOT* using any of the standard AMQ Ajax
adapters that come with ActiveMQ distribution. As I am experimenting with
Sencha Touch, I created a Sencha Touch adapter by looking at how the jQuery
one is implemented. It turned out that the adapter was working fine for
POST, but not for GET - it wasn't setting URL parameters, as you can see
from my previous message. It is fixed now.

Here is the working code:

// AMQ Ajax Adapter for Sencha Touch

var org = org || {};
org.activemq = org.activemq || {};

org.activemq.AmqAdapter = {

	init: function(options) {
	},

	/**
	 *  Implement this method to make an AJAX call to the AjaxServlet. An
	 *  options object will accompany this class and will contain the
properties
	 *  that describe the details of the AJAX call. The options object will
	 *  have the following properties:
	 *
	 *  - method:  'get' or 'post'
	 *  - data:    query data to accompany the post or get.
	 *  - success: A callback function that is invoked upon successful
	 *             completion of the AJAX call. The parameter is:
	 *             - data: The result of the AJAX call. In the case of XML
	 *                     data should resolve to a Document element.
	 *  - error:   A callback when some type of error occurs. The callback
	 *             function's parameters should be:
	 *             - xhr:    The XmlHttpRequest object.
	 *             - status: A text string of the status.
	 *             - ex:     The exception that caused the error.
	 *  - headers: An object containing additional headers for the ajax
request.
	 */
	ajax: function(uri, options) {
		
		var successCallback = options.success || function(){};
		var errorCallback = options.error || function(){};
		
		var headers = options.headers || {};
		headers['Content-Type'] = 'application/x-www-form-urlencoded';
		
		var r = {
                        url : uri,
                        method : options.method,
                        rawData : options.method == 'post' ? options.data :
null,
			params: options.method == 'get' ? options.data : null,
                        scope : this,
                        headers : headers,
                        callback: function(options, success, R) {
        		        if (success) {
        			        successCallback(R.responseXML);
        		        } else {
        			        errorCallback(R, R.responseText)
        		        }
                        }
		};
		
		Ext.Ajax.request(r);
	},

	log: function(message, exception) {
		if (typeof console != 'undefined' && console.log) console.log(message);
	}
};

-- 
View this message in context: http://activemq.2283324.n4.nabble.com/Problem-using-Ajax-to-listen-to-a-queue-topic-tp3167287p3167522.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message