2

I would like to achieve that when clicking in an image, in the div where this image is, a div with other content from another .html is loaded, but I can't get it done.

If I do, the following, it works perfectly:

$('#windows_link').click(function(){
        $('#apps_container').html("Hi!");
    });

But if I do the following, it does not work; it doesn't do anything actually:

$('#windows_link').click(function(){
        $('#apps_container').load('windows_apps.html #apps_container');
    });

Any help, please?

Thanks a lot in advance!

14
  • 1
    Have you used a tool like Firebug to determine if your 'windows_apps.html #apps_container' is actually returning anything? Commented Jul 1, 2011 at 14:22
  • Are you trying this locally? if so, in which browser? Commented Jul 1, 2011 at 14:23
  • Hi! @Gregg I haven't yet used it, but that should exist! Commented Jul 1, 2011 at 14:24
  • 2
    @noloman - that's a cross-domain request in chrome, and won't work...that's where you're getting blocked. If you try it on an actual site (or local webserver) you should be good. Commented Jul 1, 2011 at 14:26
  • 1
    @Acorn - he's trying it locally, any other path is another domain when you're local, in some browsers...and in chrome this is true. Commented Jul 1, 2011 at 14:27

2 Answers 2

3

When you're local any other HTML path is treated as another domain in certain browsers (Chrome is on the list). That means any AJAX request (what .load() does underneath) you attempt will be blocked by the same origin policy.

What you have will likely work fine...just not locally, in Chrome.

You can verify this by testing in another browser like Firefox, or by launching chrome with a command line switch to disable this safety feature (only for testing!, turn it off after):

chrome.exe --disable-web-security
Sign up to request clarification or add additional context in comments.

3 Comments

Wonderful, so I will just try in another browser and trust that it'll work when uploaded to a web server. Thanks everybody for your help!
@noloman: Really, unless you have a good reason not too, it is better to test develop on a server that has the same environment as the site will eventually be hosted on. Preferably that server. Otherwise there may well be unforeseen differences, like this.
@noloman - I'm with orbling here, setup a localhost web server (lots of free options there) to do your testing and you'll be much happier (and less pushing to another site to test the small stuff).
0

If the first try works correctly, i assume the problem is here

.load('windows_apps.html #apps_container');

When you click the link, do you see a call in your .net panel of firebug or of your debugging console(does the ajax call complete succesfully)?

Is windows_apps.html in the same folder of the page script that calls it?

is there a div called apps_container into that page?

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.