how to make jsonp calls dynamically

Hi there,

I need to be able to have one of my web server pages get data (on user request) from another server of the same origin policy is the problem I am working around here.  

I have used the following javascript approach to make a single cross domain call to the other server.  I use a callback parameter as shown in numerous examples out there.  And I use the approach of creating a script element and insert the script into the page shown here:

A sample page on

	function processJSON (inData) {

	  // Do something with the JSON response
	// Create a new script element
	var script_element = document.createElement('script');
	// Set its source to my target server
	script_element.src = '';
	// Put the script element in the page head

Open in new window

For me, this is a simple way to get back some html sub-components from another server of mine.

So, my question is this:  How do I do this multiple times?   This technique will continue to append script elements into the page head in order to get them to fire and that seems rather unhealthy, yes?  To continue to plug more and more of them into the head?

I have a few pages in my system where staff may make 10 or twenty such calls and I am looking for some assistance as to the best way to do this with this jsonp approach.  Essentially have this associated with a button or link that when clicked will accomplish a cross-domain task like this over and over again upon request.

Many thanks, in advance, for any assistance in this regard.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
Are you able to use a library such as jQuery to do your JSONP requests?
srbarker8Author Commented:
Hi ... yes, I can ...

If there is an easier approach using jquery, I would appreciate some help with that approach.

Thx Scott
you can use this :
check the examples and what it do
RobOwner (Aidellio)Commented:
jQuery will be the easiest:

include it in your <head> like this: <script src=""></script>

then it's as simple as this
$(function() {
		tagSource:function( request, response ) {
				url: "",
				dataType: "jsonp",
				data: {
					q: request.term
				success: function( data ) {
					response( data );
		triggerKeys:['enter', 'comma', 'tab'],
		allowNewTags: false

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
srbarker8Author Commented:
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.