Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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