2

How should I do to attach directly the params via post method with ajax.updater defined in prototype library?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

6 Comments

In my scenario, I have to pass values body as well as parameter in POST Method. What to do now ? Any ideas much appreciated.
@user2959196 it's not clear from your comment if you mean by parameters - URL parameters. If so you can just concatenate those parameters in the URL
@mhiza Really sorry for putting up a comment in a wrong way. I have to pass two different contents in POST method call. content 1 - pass via body. content 2 - pass via parameters. Both contents has to be supplied in a same AJAX call. HOW TO DO IT ! ! !. Prototype is providing 'postBody' attribute to pass via body. and 'parameter' attribute to pass via url. But I when i add the both content , It is not helping me.
new Ajax.Updater('section', '/url?parameter=value', { postBody: content }); ?
If it is a post method parameter, may i append it directly in the Url like the following url?parameter=value
|
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.