3

currently i am calling a script something like this:

<script src="http://example.com/checkout.js" class="stripe-button"
      data-description="Access for a year"
      data-amount="5000">
</script>

is it possible to use the data attributes (data-description, data-amount, etc) using jQuery-getScript?

i would like to do something like this:

jQuery.getScript('http://example.com/checkout.js',
      {    data-description:"Year Access",  /*this is just a guess*/
           data-amount:"5000"   },          /*but probably wont work*/
      function( data, textStatus, jqxhr ) {
 });

i realize that getScript is shorthand ajax, but i cannot determine where the data-attributes might be included.

down-voters: i honestly did try to research this but could not find any examples.

edwardsmarkf
  • 1,387
  • 2
  • 16
  • 31
  • 2
    It's possible to get the `data` attribute values from the element, but it's entirely moot in this case as you cannot provide any parameters to the `$.getScript` call. http://api.jquery.com/jQuery.getScript/ – Rory McCrossan Jul 09 '16 at 19:56
  • 1
    I'm guessing Stripe made it so their script had to be added with a script tag on purpose. – adeneo Jul 09 '16 at 19:57

1 Answers1

0

getScript removes the script element used to eval the code:

function DOMEval( code, doc ) {
    doc = doc || document;

    var script = doc.createElement( "script" );

    script.text = code;
    doc.head.appendChild( script ).parentNode.removeChild( script );
}

So there is no point in adding attributes to it, because it's no longer there and probably has been garbage collected.

Oriol
  • 274,082
  • 63
  • 437
  • 513