how can I remove my appended script because it causes some problems in my app.
This is my code to get my script
var nowDate = new Date().getTime();
v
In case of JSONP and your use of jQuery, why not take full advantage of jQuery's JSONP loading facilities, which do the post-clean-up for you? Loading JSONP resource like this, doesn't leave a trace in the DOM:
$.ajax({ url: 'http://example.com/', dataType: 'jsonp' })
The <script>
tag used for loading is removed instantly as soon it's loaded. If the loading is a success. On the other hand, failed requests don't get cleared automatically and you have to do that yourself with something like this:
$('head script[src*="callback="]').remove();
called at the right time. It removes all pending JSONP <script>
tags.
I would simply check to see if you've already added the script. Adding it and then removing is adds unnecessary complexity. Something like this should work:
var scriptAdded = false;
if(scriptAdded == false) {
document.body.appendChild(script);
scriptAdded = true;
}