Skip to content

Instantly share code, notes, and snippets.

@douglas-vaz
Created August 9, 2012 16:39
Show Gist options
  • Save douglas-vaz/3305731 to your computer and use it in GitHub Desktop.
Save douglas-vaz/3305731 to your computer and use it in GitHub Desktop.
Cross domain request using callback added to a dynamic script element
<!DOCTYPE html>
<html>
<head>
<!--
Enter your script name in the text box and hit submit. Have a callback in the url and the form data. The callback function should execute.
-->
</head>
<body>
<form>
<input type="text" id="value"/>
<input type="button" id="sub" value="Submit" onclick="foo()"/>
</form>
<div id="dump">
</div>
<script type="text/javascript">
<!--
function foo()
{
var val = document.getElementById('value').value;
var url = val;
var elem = document.createElement('script');
elem.setAttribute('type','text/javascript');
elem.setAttribute('src',url);
document.body.appendChild(elem);
}
-->
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment