How should I do to attach directly the params via post method with ajax.updater defined in prototype library?
2 Answers
The implicit method used by prototype is POST and you got two possibilities to submit post data. Either via the parameters option, or via the postBody parameter.
new Ajax.Updater('id_of_html_to_be_updated', 'url', {
parameters: {
id: 1,
name: "string"
}
});
// OR
new Ajax.Updater('id_of_html_to_be_updated', 'url', {
postBody: 'id=1&name=string'
});
In the first version prototype converts the parameters option to a query string, while in the second example you explicitly state the query string in the postBody parameter.
6 Comments
new Ajax.Updater('section', '/url?parameter=value', { postBody: content }); ?You supply them via the parameters option:
new Ajax.Updater('targetId', '/your/url', {
parameters: {
foo: "fooValue",
bar: "barValue"
}
});
See the docs for details; docs for the various common Ajax options are here. The above updates the element with the ID "targetId" with the results of POSTing the parameters foo and bar to /your/url. Because I've supplied the parameters as an object, Prototype handles applying encodeURIComponent to them for me.