Skip to content

Instantly share code, notes, and snippets.

@vfontjr
Created May 2, 2020 16:30
Show Gist options
  • Save vfontjr/f05ed1ee7b94f7f3c5adab6810361fdc to your computer and use it in GitHub Desktop.
Save vfontjr/f05ed1ee7b94f7f3c5adab6810361fdc to your computer and use it in GitHub Desktop.
jQuery(document).ready(function ($) {
"use strict";
function set_form_fields(data) {
$("#html_display_element").html(data);
$("#field_confirm_value").attr("value", data ); // One way to set a value. Could also use $("#field_confirm_value").val( data );
}
$("#btnSubmit").on( "click", function (e) {
e.preventDefault();
var confirmation_req = $.ajax({
type: 'GET',
url: 'my_processing_script',
dataType: "text",
contentType: "text/xml",
data: { FormXml: strXml },
dataFilter: function (data, type) {
var start = data.search('">') + 2, strlen = data.search('</long>') - start;
return data.substr(start, strlen);
}
});
confirmation_req.done(function(data) { set_form_fields(data); }); // fires on successful return of data
confirmation_req.always(function() { $("#form_key").submit(); }); // always fires on completion of ajax request regardless of success or failure
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment