Dave's Brain

Browse - programming tips - javascript include

Date: 2009oct15
Language: javaScript

Q.  How can I do a C-like #include in javaScript?

A.  There is no equivalent to a #include is javaScript.
But you can use Ajax to pull in a .js file and then run it!

Here's how to do that with jQuery:

	$.ajax({
  		type: 'GET',
  		url: 'my_include.js',
  		dataType: 'script'
	});

You can do this in pure javaScript too.
Search for "Ajax" here for more info.
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2010, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.