How to include a file with jquery?

Posted on 2011-04-29
Medium Priority
Last Modified: 2012-08-12
I am wondering what is the jquery equivelent to php's include:

include 'sidebar.php';

I have a link:

<a href="">+ Add A Sub Category</a>

But I am not sure what I would set the href to in order to get the included file.  Anyone got some advice for this?
Question by:FairyBusiness
  • 4
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35496261
LVL 20

Accepted Solution

Proculopsis earned 2000 total points
ID: 35496306

The load method should do what you want:

$("#load-me").load( "http://www.google.co.uk/" )

<div id="load-me"></div>

Author Comment

ID: 35497187
Ok, I changed my function to this:

$("#sub").click(function() {
      content = "<div class='sub'></div>";

My thought is every time my link (#sub) is clicked

 <a href="" id="sub">+ Add A Sub Category</a>

It would add a div to my form

Then it would load the included file into that div with a class of sub.

Then it would finally fade the div in.  The reason I am doing it like this is because there may be many sub categories so I need it to be able to be entered in to the form multiple times.  But its not working.  Any ideas on how I could achieve this?
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 35498433
Here is the function in my library (I didnt get very far with it yet)

function update_materials() {
	global $conn, $message, $errors, $error;
	if(empty($errors) && isset($_POST['submit'])) { // Perform Update
		$materials = $_POST['materials'];

Open in new window


Author Comment

ID: 35498486
Nevermind that comment was suppose to be for another question. ..

Author Closing Comment

ID: 38285699

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question