I am creating a widget that pulls HTML content from a URL Path with specified parameters.
The widget needs to be allowed to appear on multiple areas of the website owner.
Here is the front-end javascript
<script src="http://www.thecashwidget.com/widget/scripts.js"></script>
<script>
aditize.init(["021232f297","4","1","myDiv,myDiv2"]);
</script>
here is the content of scripts.js
var aditize = aditize || (function() {
var _args = {}; // private
// Localize jQuery variable
var jQuery;
jQuery = window.jQuery;
function scriptLoadHandler() {
jQuery = window.jQuery.noConflict(true);
}
return {
init : function(Args) {
_args = Args;
var container = _args[3].split(',');
jQuery(document).ready(function($) {
for (i = 0; i < container.length; i++) {
var getJSONURL = 'http://www.thecashwidget.com/widget/frame.php?callback=?&c='+ _args[1] + '&r=' + _args[2];
$.getJSON(getJSONURL,'id=' + _args[0], function(res){
$("#" + container[i]).html(res.data);
});
}
});
}
};
})();
This line in particular stops the code from working
$("#" + container[i]).html(res.data);
when I hardcode the value "i", it works
$("#" + container[0]).html(res.data); // this works
This line is important because it reads the 4th parameter of the Init sequence. The 4th parameter includes an array of containers where the widget should be placed. In our example, we have myDiv and myDiv2. With everything running smoothly, we should have a 4 by 1 widget in container with id="myDiv" and another 4 by 1 widget in a container with id="myDiv2".
I have tried this
<script src="http://www.thecashwidget.com/widget/scripts.js"></script>
<script>
aditize.init(["021232f297","4","1","myDiv"]);
aditize.init(["021232f297","1","4","myDiv2"]);
</script>
And that does not work either. Can anyone point out why the code is not allowing me to getJSON multiple times?