开发者

Get php from the same folder

开发者 https://www.devze.com 2023-02-08 06:07 出处:网络
func.js: $.get( \"test.php\", {id: theid}, function(data){...} ) My test.php and func.js files are inside /scr开发者_运维知识库ipts/data/ folder, full url for php is http://site.com/scripts/data/t

func.js:

$.get(
    "test.php",
    {id: theid}, 
    function(data){...}
)

My test.php and func.js files are inside /scr开发者_运维知识库ipts/data/ folder, full url for php is http://site.com/scripts/data/test.php

How do I get php file without usage of relative path?

This script should work on other domains too.

Thanks.


You can just use a relative path:

$.get(
    "/scripts/data/test.php",
    {id: theid}, 
    function(data){...}
)


You can use relative paths in the get, such as "/scripts/data/test.php". See the get documentation for jquery here: http://api.jquery.com/jQuery.get/ The example there uses 'ajax/test.html'.

Hope that helps.


For URLs you have 3 options.

  • absolute URIs (with domain)
  • absolute relative URIs (without domain, but the full path; these start with /)
  • relative URIs

If your problem is that the places (URI paths) you use your JS script which is in a separate JS file varies but you don’t want to use absolute URIs nor absolute relative URIs then you should improve your JS scripts design.

You should make the script itself path-independent and the webpage using the JS script should pass the path to a root folder or the scripts/data folder, or some other base-path of your application to the JS script.

0

精彩评论

暂无评论...
验证码 换一张
取 消