ajax url path

Discussion in 'PHP' started by Hubert jiang, Apr 1, 2015.

  1. #2
    Hi Guys.

    I have a ajax.php at C://xampp/htdocs/myWebsite/autocomplete/ajax.php

    where all the queries and data retrieved from MySQL are stated in here.

    Then I have a auto.js at C://xampp/htdocs/myWebsite/autocomplete/js/auto.js
    auto.js:
    $('#countryname_1').autocomplete({
                          source: function( request, response ) {
                              $.ajax({
                                  url : 'ajax.php',
                                  dataType: "json",
                                data: {
                                   name_startsWith: request.term,
                                   type: 'country_table',
                                   row_num : 1
                                },
                                 success: function( data ) {
                                     response( $.map( data, function( item ) {
                                         var code = item.split("|");
                                        return {
                                            label: code[0],
                                            value: code[0],
                                            data : item
                                        }
                                    }));
                                }
                              });
                          },
                          autoFocus: true,             
                          minLength: 0,
                          select: function( event, ui ) {
                            var names = ui.item.data.split("|");
                            console.log(names[1], names[2], names[3]);                        
                            $('#country_no_1').val(names[1]);
                            $('#phone_code_1').val(names[2]);
                            $('#country_code_1').val(names[3]);
                        }                 
                      });
    Code (markup):
    my index.php is in C://xampp/htdocs/myWebsite/ABC/index.php

    Any idea how should
    url: 'ajax.php'
    Code (markup):
    be? I tried
    url: '../autocomplete/ajax.php'
    Code (markup):
    but to no avail.
     
    Hubert jiang, Apr 1, 2015 IP
  2. ahmadmarafa

    ahmadmarafa Member

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    just use ajax.php full URI like ht tp://<yoursite>/ajax.php
     
    ahmadmarafa, Apr 1, 2015 IP
  3. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #4
    Technically, if your site is at ABC/, the rest of the folders and files should be subfolders to that folder - normally, on a production server, this will be root, and accessing folders above root is NOT recommended, and might not even be possible
     
    PoPSiCLe, Apr 1, 2015 IP