Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagejs
linenumberstrue
require(["t5/core/ajax", "jquery"], function (ajax, $) {
    // Creating a callback to be invoked with <p id="result"> is clicked.
	$('#result').click(function() {
		ajax('answer', { 
			element: $('#componentParagraph'), $('#result'), // This doesn't need to be the same element as the one two lines above
            // Callback called when the request is finished. 
            // response.json is the object returned by the event handler method
			success: function(response) {
				$('#result').text(response.json.origin);
			}
		});
	});
});

 

 If you're trying to invoke a page class event handler, you can change line 5 above to element: null. You do need to explicitly set the element property, otherwise the ajax function will treat the first parameter, url, as an URL and not as an event name.