2

Does anyone know how to get file from parent directory using $http.get?

The system works fine if I use $http.get("customers.php") (file customers.php produce json format data) where customers.php is in same directory but if I switch customer to parent directory, system doesn't work (using this expression $http.get("../customers.php") ).

I only use AngularJS.

5
  • What doesn't work about it? Errors in console? Any request in the Network activity? Commented Apr 21, 2015 at 7:20
  • 1
    What if you pass the entire path? Commented Apr 21, 2015 at 7:21
  • 1
    try $http.get("./../customers.php") i think this will work. Did work for me. Basically ./ and then the path. Commented Apr 21, 2015 at 7:21
  • I try with ../customers.php but doesn't work. It doesn't work even with ./../customers.php or just with ../customers.php. Commented Apr 21, 2015 at 8:13
  • There is nothing in web console. Commented Apr 21, 2015 at 8:21

2 Answers 2

2

Best practices will be provide complete URL.

Such As:

$http.get("http://example.com/customers.php")

Or you can use ../ instead of it.

Sign up to request clarification or add additional context in comments.

6 Comments

Thank's for quick replay. But this doesn't work because the file is hidden from users, out of working directory. Do you have another solutions?
Doesn't matter that it was hidden or not. It only can send a http request to your customers.php file. If you are not clear provide some code.
I use https protocol and it works fine when file is in current directory. Like server.ip/customers.html
If I switch same file in parent directory, I get nothing in the browser and there is no error in the browser console.
Here I send you a code: <script> var app = angular.module('myApp', []); app.controller('customersCtrl', function($scope, $http) { $http.get("./../raspored_ispita_list.php") .success(function (response) {$scope.names = response.records;}); }); </script>
|
0

I'm quite sure that answer you get is not a solution for your problem. If it is true what you said, when file customers.php is not in the root of web directory, which means is hidden from url, then you can not solve problem with the help of $http.get function. Suppose that we have

/var/www/public directory

and the file customers.php is in next directory

/var/customers.php

Your root directory of your web server is

/var/www/public

with your AngularJS files, like *.html or customers.html.

If someone enter this url

www.serverip.com 

Your web server point to this directory /var/www/public/customers.html and you want to read file from /var/customers.php with $http.get fuction.

You can not do that.

You must put customers.php in the root of your web server. For instance, in the next directory

/var/www/public/customers.php

Thanks for your attention.

1 Comment

Thank you Arsenije. It was verry nice from you to explain how $http.get function works. Thanks again.

Your Answer

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