BenYacine
BenYacine

Reputation: 35

Getting the host URL + the destination URL when

I am using an Ajax POST call to get some data from a file located on an other server, but I am getting my host URL + the destination URL as URL for my AJAX URL!

How could I get the destination URL only?

var url = "192.168.1.7/var/www/html/pfe/ajax.php";    
$("#c1.on").click(function () {
$.ajax({
        url: url,
        type: 'POST',
        data: { on : true, pin : 16 },
        success: function(data){
            $("#c1.on").addClass("hide");
            $("#c1.off").removeClass("hide");
        }
    });
});

The URL I get: 192.168.1.2/192.168.1.7/var/www/html/pfe/ajax.php

Upvotes: 1

Views: 118

Answers (1)

Barmar
Barmar

Reputation: 780984

The URL syntax is incorrect. If a URL doesn't have // in it, it's treated as a filename on the same server as the current page. So it should be:

var url = "//192.168.1.7/var/www/html/pfe/ajax.php";    

The // indicates that the next component is the name or address of the server.

Not that this still may not work because of the restriction against cross-domain AJAX.

Upvotes: 1

Related Questions