0

Have problem with this code

var MAIN_LOCATION = "http://www.bosscaffe.com/new/";
$("#gallery_page").click(function() {
    $('#gallery_photos').show();
    getPhotos();
    return false;
}); 

function getPhotos()
{
    $.ajax({
         type: "GET",
         url: MAIN_LOCATION + "classes/getEnterijerPhotos.php?lang="+LANG,
         success: function(msg){
            if (msg != 'nothing')
            {
                $('#photo_wrapper').empty();
                $('#photo_wrapper').append(msg);
            }
         }
    });
}

I tried several things like crossdomain: true, async:false, etc...I tried to switch it to POST, but from some reason this one does not return anything if I fire call in new tab, I get result http://www.bosscaffe.com/new/classes/getEnterijerPhotos.php?lang=en so all of those images are prepared, on my local instance this works but on server it doesn't at all, in Chrome I get status = canceled, any thoughts about this one?

In any case end solution would be to transfer it to JSON, but strange thing that such a functionality not working on same domain.

vaske
  • 9,332
  • 11
  • 50
  • 69
  • What is `MAIN_LOCATION`? Does it end in a slash? eg `http://www.somedomain.com/` or `http://www.somedomain.com`? – Richard Parnaby-King Sep 11 '12 at 14:39
  • Try building out the `complete:` and `failure:` functions and see what they report in the console. – Dameo Sep 11 '12 at 14:42
  • @Chase yes, please ignore it. – vaske Sep 11 '12 at 14:43
  • did u check it on firefox ? the canceled status is a bug in chrome check this http://stackoverflow.com/questions/8227422/getscript-returns-status-canceled-and-the-application-does-not-execute-the-cal – Prog Mania Sep 11 '12 at 14:43
  • @Dameo - strange is that can't reproduce on my local envy, it works as a charm on local, but have server issue. – vaske Sep 11 '12 at 14:44
  • @Richard Parnaby-King I just update code... – vaske Sep 11 '12 at 14:45
  • @Prog Mania of course that I tried it in FF there I get empty response like there is no response http status 200 OK – vaske Sep 11 '12 at 14:46
  • The html in the link is malformed. I'm not sure if that would have any effect? You have `div`s around `li` elements instead of `ul`... – Richard Parnaby-King Sep 11 '12 at 15:01
  • @VDP I use that way just update var MAIN_LOCATION = "http://www.bosscaffe.com/new/"; -it looks like that on server – vaske Sep 11 '12 at 15:23
  • yes but where is the page using the javascript (=origin of calling page)? Is it also on `http://bosscaffe.com` (=origin of called page)? btw: If you open the page in chrome and check the console you will find a cross-origin error if that is the issue – VDP Sep 11 '12 at 15:28
  • @VDP aha that means this will works letter on when I place it on from new to http://bosscaffe.com right? – vaske Sep 11 '12 at 15:36

2 Answers2

1

Are you making a cross origin call? => is the origin of your calling page the same as MAIN_LOCATION (same protocol, same domain, same port).

So if you're MAIN_LOCATION = 'http://www.bosscaffe.com/new/classes/getEnterijerPhotos.php?lang=en' then the calling page needs to start with http://www.bosscaffe.com/...

If it is a cross origin call and you want to get it fixed (without moving it to the same origin) I posted an answer on that issue here

Community
  • 1
  • 1
VDP
  • 6,340
  • 4
  • 31
  • 53
  • you can try yourself http://www.bosscaffe.com/new/en/#galerija click on Interior or retro, town date what ever, seems like not an cross origin call. – vaske Sep 11 '12 at 15:32
0

You don't provide enough information to answer your question but here are a few things to consider:

There is a typo in your first line where you have an extra 'l' (el) in galllery.

As previously noted, if you expect the reply to be a particular datatype, you need to list it in the arguments to $.ajax() so the code can prepare its result properly.

And it's usually a good idea to provide an error handler on all AJAX requests so you know the request has actually succeeded. In your code, your request can fail ("silently") without giving you any indication of the fact.

EDIT

If you're making the request from the same host that is running your PHP server process, I suspect you'll need to use the server's fully qualified hostname rather than 'localhost' in your URL.

Rob Raisch
  • 17,040
  • 4
  • 48
  • 58
  • for 1. ignore that, for second yea dataType should be html in this case, and for third I agree. – vaske Sep 11 '12 at 15:00
  • yup but typo is not main question here, strange thing is if I open that URL I see response and I see it working through my localhost, but on server it doesn't work... – vaske Sep 11 '12 at 15:01
  • On server? You mean when you open the URL using a browser on the same computer running the PHP server process? – Rob Raisch Sep 11 '12 at 15:07
  • No I man on my remote/public web server, on local Apache it works fine. – vaske Sep 11 '12 at 15:20
  • Does the browser console list any error messages? When you add an error handler, does it report any errors? – Rob Raisch Sep 11 '12 at 15:28