PHP变量到JQuery函数?

fil*_*ter 4 php jquery

我在这个函数中需要一个相对路径:

    $(function() {
            $("#searchbox").autocomplete({
                    minLength : 2,
        source    : function (request, response){
                                $.ajax({
                                    url      : "http://linux/project/index.php/main/search/",
                                    dataType : "json",
                                    data     : { key : request.term},
                                    type     : "POST",
                                    success  : function(data){
                                    response($.map(data, function(item) {
                        return {
                            label: item.original_name,
                            value: item.original_name,
                                                            id   : item.project_id+"/"+item.folder_id+"/"+item.id
                        }
                    }))

                                           }
                            })
                            },
                    select : function(event, ui) {
                                document.location.href = "http://linux/project/index.php/projects/loaddocument/"+ui.item.id;
                             }

    });
});
Run Code Online (Sandbox Code Playgroud)

如何在上面的函数中使用PHP变量路径替换http:// linux/project

最好的祝福 ...

dec*_*eze 5

url : "http://<?php echo $path; ?>/index.php/main/search/"
Run Code Online (Sandbox Code Playgroud)

或者,如果脚本位于单独的.js文件中,则如下所示:

// in the main page
<script type="text/javascript" charset="utf-8">
    var config = { basePath : '<?php echo $path; ?>' };
</script>

// in the .js file
url : "http://" + config.basePath + "/index.php/main/search/"
Run Code Online (Sandbox Code Playgroud)