Javascript button error

Hi,

I am using the code below to create a pdf via Docuprint. It creates the file fine, but comes up with the error message, and the spinner doesn't disappear. Where am I going wrong?

Cheers

Craig

$(document).on('knack-scene-render.scene_98', function(event, scene) {

$('#view_182').before('<div style="padding:15px"><a href="#" id="pdf" class="kn-button">Send to pdf</a></div>');

// link hander: send to pdf
$('#pdf').click(function(event) {
event.preventDefault();

// get data
var data = Knack.models['view_182'].toJSON();

log('data!');log(data);
Knack.showSpinner();

$.ajax({
url: 'https://dashboard.docupilot.app/documents/create/04f1b0bd/123e0a3a',
data: {
issue: data.field_9_raw,
otherinfo: data.field_17_raw,
},
type: 'POST',
success: function() {
alert('pdf Created!');
Knack.hideSpinner();
},
error: function() {
alert('There was an error creating the pdf');
}
});
});

});

 

Oops I thought you said it won’t appear. For it not disappearing put a short delay in before the remove function and it will disappear.

Hi, It makes no difference. So same result if the spinner function is in the code or not. The file writes correctly; the "success" message doesn't appear; the "error" appears; and the spinner stays spinning.

If you remove the hide spinner function does it appear?

Hi, Yes it is the last line in the array. 

I think you are correct, but still makes no difference if I remove the comma.

Thanks