4

I want to inject script like this using jQuery getScript function

<script type="text/javascript"
        src="https://app.test.com/test.js"
        data-client-key="321jj33-dasd333"
></script> 

I want to add that extra variable with its value which is data-client-key.

What I've done so far is like this:

var test = "https://app.test.com/test.js";

$.getScript(test, function(){
  $.ajax({    
    //post data using ajax
  });
});

1 Answer 1

5

You can create a script tag with jQuery like this

var script = $("<script>");
script.attr("src", "YOUR_URL");
script.attr("data-client-key", "CLIENT-KEY");
$("head").append(script);

Hope it help you

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.