postGet (JS API v2)

Version 2 API only.

postGet

Method Signature

void ultraCart.util.postGet(String url);

Description

  1. Accepts a url and parses it up into server name and query parameters
  2. Constructs a form and adds elements to it for each query parameter
  3. Points the form to the url, and sets the method to post
  4. Submits the form

Parameters

String url - the complete url that needs POSTing

Result

no return value. after the submit, the page will change.

This method is commonly used to POST the redirect url during cart finalization to prevent the user from hitting the back button (so easily).
Here is a code snippet from a checkout() button implementation.

    ultraCart.saveFieldElements(function (){
      ultraCart.checkout(checkoutMethod || ultraCart.checkouts.CHECKOUT_ULTRACART, {async:true, onComplete:function(result){
        if(result.redirectToUrl){
          ultraCart.util.postGet(result.redirectToUrl); // post instead of redirect to discourage back button use.
        } else if(result.errors) {
          finalizing = false;
          renderErrors(result.errors);
        } else {
          finalizing = false;
          // ?? this should never happen.
        }
      }})
    });