2

I am setting up a twitter feed into my site and have it working perfectly when you access it with a root page ie www.domain.com/index.php

However when you have a url that is www.domain.com/category/page it doesn't not work, however if you use www.domain.com/index.php?cat=category&page=page it works fine.

So in the javascript I have the following

jQuery(function() {
    jQuery.getJSON('cache/twitter-json.txt', function(data){
    jQuery.each(data, function(index, item){
    jQuery('#tweet').append('code for displaying tweet');
});
});

So I have tried to change the url in the getJSON function to the full path www.domain.com/cache/twitter-json.txt but that doesn't work.

3 Answers 3

8

Try:

jQuery.getJSON('/cache/twitter-json.txt', function(data){

Relative URLs are interpreted relative to the directory of the page containing the reference. So when you make the above call from www.domain.com/category/page, it tries to go to www.domain.com/category/cache/twitter-json.txt.

If you want to use the full URL, you need to put // before the hostname, e.g.

jQuery.getJSON('//www.domain.com/cache/twitter-json.txt', function(data){

Otherwise, it thinks www.domain.com/ is just another level of directory.

Sign up to request clarification or add additional context in comments.

7 Comments

Thanks Barmar that make sense but unfortunately thats not fixed it, it has also stop working in the domain.com/index.php
Maybe there's a rewrite rule that's messing with it? Otherwise, it should work like this.
The only rewrite rules i have are RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L] RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&game=$2 [L]
Can you check your access log to see what URL it's trying to access for twitter-json.txt, and compare that with where the file really is?
Nothing in there that is telling what is causing the issue, the file paths look right
|
2

change

jQuery.getJSON('cache/twitter-json.txt', function(data){

to

jQuery.getJSON('/cache/twitter-json.txt', function(data){

Comments

-1

Maybe it helps to set the base in your html

<base href="http://myserver/dir1/">

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.