O
O
Oleg Otkidach2020-08-31 17:24:05
PHP
Oleg Otkidach, 2020-08-31 17:24:05

What to write as url in fetch js command when working on OpenServer on local computer?

I'll make a reservation right away, I'm a beginner, I know little.

I have OpenServer installed on my local computer.
Installed in order to be able to work with php.

Now I am trying to solve the following problem.
My php file opens (file_get_contents) some external html file from web.
Further, it edits the received string in some way, in particular, what is important, adds
" " to it. Next, it prints (echo) it, as a result of which my myScript.js works out. myScript.js gets some js object obj. Now I want to send this json to the server (so that I can then process it using php). To do this, I write at the end of my myScript.js a construction like<script src='myScript.js'></script>

fetch('url', {
    method: 'post',
    headers: {
        'Accept': 'application/json, text/plain, */*',
        'Content-Type': 'application/json'
    },
    body: 'json=' + JSON.stringify(obj)
})


I got stuck on what to write as url.
Tried everything, no result yet.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
McBernar, 2020-08-31
@Allegro75

The URL where your php script is available. localhost/script.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question