Skip to content

Instantly share code, notes, and snippets.

@vfontjr
Created May 2, 2020 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vfontjr/1a305400a481ee5c23835c83593f87a6 to your computer and use it in GitHub Desktop.
Save vfontjr/1a305400a481ee5c23835c83593f87a6 to your computer and use it in GitHub Desktop.
var confirmation_req = $.ajax({
type: 'GET',
url: '//path-to-remote-server',
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);
}
});
var confirmation_req = $.ajax({
type: 'POST',
crossDomain: true,
url: '//path-to-remote-server',
dataType: "text",
data: { FormXml: strXml },
dataFilter: function (data, type) {
var start = data.search('">') + 2, strlen = data.search('') - start;
return data.substr(start, strlen);
}
}).fail(function (jqXHR) {
write_to_log("Ajax submission failed");
write_to_log("Content sent to server: " + strXml);
write_to_log("Status: " + jqXHR.status + '\r\n' + "Status code: " + "Status message: " + jqXHR.statusText);
alert("There was an error retrieving the confirmation number from the server. Please try submitting your form again later.");
}).done(function (data) {
if ($.isEmptyObject(data) || data === "0") {
write_to_log("Empty confirmation number in done function");
write_to_log("Content sent to server: " + strXml);
alert("There was an error retrieving the confirmation number from the server. Please try submitting your form again later.");
} else {
write_to_log("Success! We're done");
set_form_fields(data);
display_confirmation();
}
}).always(function () {
write_to_log("Submitting form");
$("#my_form").submit();
});
function htmlDecode(value){
return $('
').html(value).text();
}
function htmlEncode(value){
return $('
').text(value).html();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment