jQuery's documentation is pretty good start for this:
http://api.jquery.com/submit/
> the browser wouldn't redirect to some php server response
So you want to suppress the standard browser handling of form
submissions and manually perform an XHR instead. Here's some sample code
that should help get you started:
---------------
(function($) {
var uri = "http://example.org";
var callback = function(data, status, xhr) {
console.log(data); // XXX: DEBUG
};
var errback = function(xhr, error, exc) {
console.log(error); // XXX: DEBUG
};
var submitHandler = function(ev) {
var value = $(this).closest("form").find("[name=foo]").val();
var data = {
foo: value
};
$.ajax({
url: uri,
type: "POST",
data: data,
success: callback,
error: errback,
dataType: "json"
});
return false;
};
var form = $("<form />").
append('<input type="text" name="foo" value="lorem ipsum" />').
append('<input type="submit" />').
submit(submitHandler).
appendTo(place);
})(jQuery);
---------------
FWIW, there are plenty of elaborate, real-world samples in the
TiddlySpace repository:
http://github.com/TiddlySpace/tiddlyspace/tree/master/src/plugins/
-- F.
--
You received this message because you are subscribed to the Google Groups
"TiddlyWikiDev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/tiddlywikidev?hl=en.