user3671491
user3671491

Reputation: 99

use relative path in jQuery load

I have a .load jquery running in a file which I am accessing from this url

http://example.com/site_folder/case-studies/firstcase

Now the file has been saved under this directory

site_folder (dir)
     assets (dir)
        case_study_content (dir)
             file.txt (file)

My code is

$( "#slider li#"+nextId ).load( "../assets/case_study_content/file.txt #pickup");

it doesn't load the file content.

Now if I keep the file under site_folder and do the load as

 $( "#slider li#"+nextId ).load( "file.txt #pickup");

it works fine.

Upvotes: 0

Views: 3094

Answers (1)

Guffa
Guffa

Reputation: 700342

When you use a relative path, it's irrelevant where you loaded the script from. The path is relative to the page that loaded the script.

If your page is inside the site_folder folder, then you use this to load the file:

$("#slider li#" + nextId).load("assets/case_study_content/file.txt #pickup");

Upvotes: 1

Related Questions