Skip to content

Instantly share code, notes, and snippets.

@rickydazla
Created December 10, 2015 03:13
Show Gist options
  • Save rickydazla/45a3c719cfb498997d7b to your computer and use it in GitHub Desktop.
Save rickydazla/45a3c719cfb498997d7b to your computer and use it in GitHub Desktop.

Revisions

  1. rickydazla created this gist Dec 10, 2015.
    23 changes: 23 additions & 0 deletions ajax-submit-form.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    /* Build the Shopify Parameters
    //---------------------------------------*/
    var action = '/contact?';
    action += encodeURIComponent('form_type') +'='+ encodeURIComponent('contact');
    action += '&'+ encodeURIComponent('utf8') +'='+ encodeURIComponent('✓');
    action += '&'+ encodeURIComponent('contact[email]') +'='+ encodeURIComponent(contact_email);
    action += '&'+ encodeURIComponent('contact[body]') +'='+ encodeURIComponent(contact_body);

    /* Submit the form
    //---------------------------------------*/
    $.ajax({
    type: "POST",
    async: true,
    url: action,
    error: function(jqXHR, textStatus, errorThrown) {
    // Request Failed.
    },
    success: function(response) {
    // Assume Success. 'response' is the complete HTML page of the
    // contact success form, so likely won't be helpful
    self.submit_thankyou();
    }
    });