Bikash Gyawali
Bikash Gyawali

Reputation: 1048

Parameters to dojo.xhrPost

When I use dojo.xhrGet , I use it this way to send more than one parameter via the GET

dojo.xhrGet
({
    url:"MyServerPageURL?Param_A="+"ValueA"+"&Param_2="+"Value2",
    load: function(data)
    {
        //do something
    },
    preventCache: true,
    sync: true, 
    error: function(err)
    {
        alert("error="+err); 
    }
});

How could I do similar thing (send more than one parameter) when I have to use the dojo.xhrPost instead?

Upvotes: 3

Views: 22143

Answers (3)

Praveen
Praveen

Reputation: 41

For xhrPOst, it's possible to mention the form name to be posted. thus all your form elements get posted. If you want to pass some additional parameter then use hidden variable in the form that is posted.

Upvotes: 0

ewh
ewh

Reputation: 1024

You do not want to use postData parameter unless you want to send a raw POST string. You normally want to use the 'content' parameter. For example:

dojo.xhrPost({
    url: 'http://whatever...',
    contents: {
        ParamA: 'valueA',
        ParamB: 'valueB'
    },
    load: function(response) {
        // ...
    }
});

Note: Use 'contents' works for xhrGet also, eliminating the need to build up the query string yourself and append to the URL.

Upvotes: 6

Andrei
Andrei

Reputation: 4237

Try to use postData parameter. E.g:

        var myParameters= {"Param_A":"Value_A", "Param_B":"Value_B"};

        var xhrArgs = {
                        url: "postIt",
                        postData: dojo.toJson(myParameters),
                        handleAs: "text",
                        headers: { "Content-Type": "application/json", "Accept": "application/json" },
                        load: function(data) {

                        },
                        error: function(error) {

                        }
                    }


 var deferred = dojo.xhrPost(xhrArgs);

Upvotes: 4

Related Questions