# Javascript button error

**URL:** <https://forums.knack.com/t/javascript-button-error/8411>\
**Category:** API & Custom Code\
**Created:** [June 21, 2020, 3:02am UTC](https://forums.knack.com/t/javascript-button-error/8411 "2020-06-21T03:02:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Craig\_Anderson](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/craig_anderson/32/1819_2.png) [@Craig\_Anderson](https://forums.knack.com/u/Craig_Anderson)\
**Post date:** [June 21, 2020, 3:02am UTC](https://forums.knack.com/t/javascript-button-error/8411/1 "2020-06-21T03:02:36Z")

</div>

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](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');  
}  
});  
});  
  
});

&nbsp;

---

<div class="post-metadata">

**Author:** ![TonyLewis75327](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/tonylewis75327/32/261_2.png) [@TonyLewis75327](https://forums.knack.com/u/TonyLewis75327)\
**Post date:** [June 23, 2020, 12:09am UTC](https://forums.knack.com/t/javascript-button-error/8411/2 "2020-06-23T00:09:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Craig\_Anderson](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/craig_anderson/32/1819_2.png) [@Craig\_Anderson](https://forums.knack.com/u/Craig_Anderson)\
**Post date:** [June 22, 2020, 9:46pm UTC](https://forums.knack.com/t/javascript-button-error/8411/3 "2020-06-22T21:46:33Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TonyLewis75327](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/tonylewis75327/32/261_2.png) [@TonyLewis75327](https://forums.knack.com/u/TonyLewis75327)\
**Post date:** [June 22, 2020, 8:32pm UTC](https://forums.knack.com/t/javascript-button-error/8411/4 "2020-06-22T20:32:19Z")

</div>

If you remove the hide spinner function does it appear?

---

<div class="post-metadata">

**Author:** ![Craig\_Anderson](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/craig_anderson/32/1819_2.png) [@Craig\_Anderson](https://forums.knack.com/u/Craig_Anderson)\
**Post date:** [June 21, 2020, 3:29am UTC](https://forums.knack.com/t/javascript-button-error/8411/5 "2020-06-21T03:29:23Z")

</div>

Hi, Yes it is the last line in the array.&nbsp;

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

Thanks
