tags:

views:

34

answers:

3

Hi guys,

I'm very very new to this ... so, here's my newbie question :D What's wrong with my code snippet below? I'm not getting any response from that URL. It should return the result in plain text ... am I doing this wrongly?

                $.get('http://is.gd/api.php?longurl=http://www.google.com.my/', function(data) {
                  alert(data);
                },"text");
A: 

You can't do AJAX requests if http://is.gd/ is not your server. AJAX requests works only with same domain where your code is.

antyrat
you need to use jsonp or some other techniques
Haim Evgi
Hmm .. then how would one get the response? According to the API herehttp://is.gd/api_info.phpI'm suppose to use the get method
InYourDreamz
At the server-side you can, at the client-side (using JS) not. For example write simple php file that accepts url param and truth socket or curl library connects to the is.gd website and returns result. This php file will be at the same domain as your request and problem will be resolved.
antyrat
or I could just do this instead. try { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); } catch (e) { }
InYourDreamz
But this is not cross-browser solution.
antyrat
oh ... I just needed it to work on firefox for testing purposes, maybe I should had been clear :X Sorry
InYourDreamz
A: 

Try this,

Give the relative path.

e.g. $.get('ajax/test.html', function(data) { alert('Load was performed.'); });

gsoni
+1  A: 

doing a quick test but try this:

$.get('/api.php?longurl=http://www.google.com.my/', 
        function(data)
        { 
            alert(data); 
    }
    ); 

Wont let you connect to a remote server, local only. also removed the ","text");" which you had at the end.

PHPology
http://is.gd is not his website and domain, he didn't have api.php functionality at his website
antyrat
in that case he will have to write some magic code to get it working then ;-)
PHPology
I've offer to him an solution at the comments to my answer
antyrat