4

I need a relative path in this function:

    $(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;
                             }

    });
});

How can I use a PHP Variable path to replace http://linux/project in the function above?

Best regards ...

2 Answers 2

5
url : "http://<?php echo $path; ?>/index.php/main/search/"

Or, if the script is in a separate .js file, something like this:

// 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/"
Sign up to request clarification or add additional context in comments.

1 Comment

Simple and efficient. Thanks :-)
0

is there an efficient way to serialize the translation of the dayNamesMin and monthNames, or did I have to do this for each item?:

        $(function() {
            $("#datepicker").datepicker({
                dateFormat  : 'dd.mm.yy',
                showWeek    : true,
                firstDay    : 1,
                weekHeader  : 'KW',
                dayNamesMin : ['So','Mo','Di','Mi','Do','Fr','Sa'],
                monthNames  : ['Januar','Februar','März','April',
                               'Mai','Juni','Juli','August','September',
                               'Oktober','November','Dezember'],
                onSelect    : function(dateText,inst){
                              }
            });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.