0

I am trying to replace this line of HTML with some javascript code that will dynamically load the script, and provide a callback once the script is loaded.

<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="SOME VALUE HERE"></script>

I can use jquery's $.ajax() function to load the file, but how do I set the data-app-key value?

$.ajax({
    dataType : 'script',
    cache    : true,
    url      : 'https://www.dropbox.com/static/api/2/dropins.js',
    complete : onApiLoad,
});
Artur Filipiak
  • 9,027
  • 4
  • 30
  • 56
AnilRedshift
  • 7,937
  • 7
  • 35
  • 59
  • Create a hidden element (can be a span or a form element doesn't matter) with given id (dropboxjs) and set that data-app-key attribute on this element. JS file, that you are including is just trying to read the data- attribute of an element with given id. Try ` – TechMaze May 05 '15 at 18:52
  • Refer to this - http://stackoverflow.com/questions/17769688/custom-attributes-in-a-script-tag – TechMaze May 05 '15 at 18:54
  • pasted my comment as an answer so that you can mark it answered – TechMaze May 05 '15 at 23:21

1 Answers1

2

Create a hidden element (can be a span or a form element doesn't matter) with given id (dropboxjs) and set that data-app-key attribute on this element. JS file, that you are including is just trying to read the data- attribute of an element with given id. Try

TechMaze
  • 477
  • 2
  • 9