I would like to include the same javascript file more than once on a page. This is because different variables are defined using the "data" attr to get different data.
Here is an example of what i mean:
<script id="sc_widget" data-key="rsl2xlfiovx09mkwofom" data-id="jwks97n15dpqge35jfmm" src="http://example.co.uk/sc.js" type="text/javascript"></script>
<script id="sc_widget" data-key="rsl2xlfiovx09mkwofom" data-id="fw8zy246n8vhf5f8du7n" src="http://example.co.uk/sc.js" type="text/javascript"></script>
The above obviously detects and displays the information from the script twice, but the information displayed is the same for both, when it should be different.
My js file:
var key = document.getElementById("sc_widget").getAttribute("data-key");
var id = document.getElementById("sc_widget").getAttribute("data-id");
$.ajax({
type: "post",
url: "//example.co.uk/sc.php?key="+ key + "&id="+ id,
contentType: "application/x-www-form-urlencoded",
success: function(responseData, textStatus, jqXHR) {
$('.sc_ouput').html(responseData);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(errorThrown);
}
})
So is there anyway to accomplish this?
data-*attributes?