Jayul Mehta
Jayul Mehta

Reputation: 11

my $ajax call is not working

When executing the following code:

url= "http://192.168.2.171/LoginAuthentication";
$.ajax({
    url: 'url',
    type: 'GET',
    success: function(res) {
        var headline = $(res.responseText).find('a.tsh').text();
        alert(headline);
    }
});

I get this error:

Object XMLHttpRequest cannot load 'url'. Origin null is not allowed by Access-Control-Allow-Origin.

Upvotes: 0

Views: 225

Answers (2)

Adrian Heine
Adrian Heine

Reputation: 4131

Browsers do not allow you to request resources from another domain (images and script files are the notable exceptions to this rule). Refer to this documentation for details and workarounds.

Upvotes: 1

Ranjith Ramachandra
Ranjith Ramachandra

Reputation: 10764

url="http://192.168.2.171/LoginAuthentication";
$.ajax({
    url: url,
    type: 'GET',
    success: function(res) {
        var headline = $(res.responseText).find('a.tsh').text();
        alert(headline);
    }
});

But it may not work if you are not making a request to the same domain

Upvotes: 0

Related Questions