1
1
1331Doken2022-01-12 22:36:18
PHP
1331Doken, 2022-01-12 22:36:18

How to make HTTP request in angular to php file?

How to make an HTTP request in angular to a php file that is on a local server
. For example, my user.php file contains:

<?php
function get_name()
{
   $arr = ['dima', 'nikita'];
  exit(json_encode($arr);
?>

How can I arrange a request to it?

I try like this - it doesn't work

this.http.get('../php/user.php')
  .subcribe((response) => {
    console.log(response);
  })

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maksim Fedorov, 2022-01-13
@1331Doken

this.http.get('../php/user.php')

Here, for some reason, the paths are relative, but you need an absolute relative to the root of your host.
If user.php opens as domain.ru/user.php , then the code will be like this.
this.http.get('/user.php')
YOU must understand that Angular is the front, and its code is executed in the browser, so your folders and your paths are not there

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question