在jquery ajax url中包含$ _SERVER文件路径的语法? [英] syntax for including $_SERVER filepath in jquery ajax url?

查看:136
本文介绍了在jquery ajax url中包含$ _SERVER文件路径的语法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用jquery ajax将数据发送到url。我想使用php $ _SERVER放置绝对URL。这样做的语法是什么?

i am sending data to a url using jquery ajax. i want to place the absolute url using php $_SERVER. what is the syntax to do this?

这是网址中的文件路径

$_SERVER['DOCUMENT_ROOT']."/folder/file_name.php"

这是文件路径进入的功能

$.ajax({
            type: "GET",
            url: "",
            data: 'time='+ visitortimezone,
            success: function(){
                location.reload();
            }
        });

这是什么语法?

推荐答案

如果你真的想从PHP获取文档根目录,你可以尝试这样的事情:

If you really want to get document root from PHP, you can try something like this:

HTML: (将您的文档根目录放在隐藏文本字段中)

<input type='hidden' name='baseurl' id='baseurl' value='<?php echo  $_SERVER['DOCUMENT_ROOT'];?>'>

jQuery (从隐藏文本中获取jQuery中的文档根目录)字段)

       $.ajax({
            type: "GET",
            url:  $('#baseurl').text() + "/folder/file_name.php",
            data: 'time='+ visitortimezone,
            success: function(){
                location.reload();
            }
        });

如果您在PHP文件中编写JavaScript,您也可以尝试:

       $.ajax({
            type: "GET",
            url:  "<?php echo $_SERVER['DOCUMENT_ROOT'] . '/folder/file_name.php';?>",
            data: 'time='+ visitortimezone,
            success: function(){
                location.reload();
            }
        });

您也可以在JavaScript中获取主机名:

document.location.hostname

这篇关于在jquery ajax url中包含$ _SERVER文件路径的语法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆