jquery ajax & full server path

19,489

Solution 1

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

Solution 2

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.

Solution 3

Web servers do not work this way. There are obvious security reasons why. You can use a relative path though.

Share:
19,489
Enkay
Author by

Enkay

Updated on June 17, 2022

Comments

  • Enkay
    Enkay almost 2 years

    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!

  • Dmytrii Nagirniak
    Dmytrii Nagirniak almost 15 years
    Yes, but not fro cross-site requests :) This is in fact no different from using relative path. It just uses absolute path. Sometimes can be useful if you don't know at what page script will be run (so you cannot use relative path),