Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery ajax & full server path

Tags:

jquery

ajax

path

Is there a way to use a full server path instead of a url when submitting a form via ajax with jquery?

The exemple below doesn't work but it will give you an idea of what I'm trying to do. I know you can't do cross domain ajax requests but this is all on the same physical server.

I don't want to set up proxy or anything too fancy, if there's no way to do this easily I'll just move a few files on the server but I was hoping there might be an easy solution.

$.ajax({  
      type: "POST",  
      url: "/home/full/server/path/file.php",  
      data: theData,  
      success: function() {  
        $('div#success').fadeIn('fast');
      }  
    });

Thanks!

like image 211
Enkay Avatar asked Nov 26 '25 23:11

Enkay


2 Answers

Is there a way to use a full server path instead of a url when submitting a form via ajax with jquery?

You can use location to get the current server:

url: location.protocol + "//" + location.host + "/home/full/server/path/file.php"

But you cannot use absolute path for cross-domain requests.

like image 119
Dmytrii Nagirniak Avatar answered Nov 28 '25 12:11

Dmytrii Nagirniak


No, that won't work. Those are not publicly visible URIs, those are actual script paths which are not visible from the client.

like image 40
karim79 Avatar answered Nov 28 '25 14:11

karim79