Thursday, 28 July 2011

JavaScript code to submit parameters manually using Dojo xhrPost

The sample code below shows how to fill in the content variable within xhrArgs in the right way with the parameters you need to send over to the server in a Post request.
The code below is useful to manually build up the parameters list.

function verifyGiftCard(e,num) {
giftCardNumber=dojo.byId('gift_card_number_1').value;
giftCardPin=dojo.byId('gift_card_pin_1').value;

var xhrArgs = {
url: "/webapp/wcs/stores/servlet/DoPPTGiftCardsBalanceEnquiries",
content:{
'dcGiftCardNumber':giftCardNumber,
'dcGiftCardPin':giftCardNumber
},
handleAs: "text",
load: function(data) {
console.debug("AJAX call successful");
console.debug(data);
},
error: function(error) {
console.debug("An unexpected error occurred: ");
}
}

//Call the asynchronous xhrGet
var deferred = dojo.xhrPost(xhrArgs);
e.preventDefault();
}

No comments:

Post a Comment