I am calling my database via HTTP. Since it is not on the same server as my application I am using JSONP. So everytime I want to query information from my database my JavaScript function adds another script tag to the DOM tree. When my application is running for a while the source code is flooded with SCRIPT tags.
Is that just something I have to accept working with JSONP or is there another way around?
Yeah, that’s just a problem with JSONP. You can attach an
onloadhandler to thescriptelement to clean it up when it’s done (onreadystatechangefor IE).Or, since you control both servers, you can use CORS. This is less of a hack than JSONP, and offers the flexibility of
XMLHttpRequest.