Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $post=file_get_contents('php://input');
- $post=json_decode($post);
- $post=json_encode($post->imie);
- echo $post;
- <!DOCTYPE html>
- <html lang="en" dir="ltr">
- <head>
- <meta charset="utf-8">
- <title>szymon trzciński z prabut to huj</title>
- <script src="nazwiska.js"></script>
- </head>
- <body>
- <form class='dane' method="POST">
- <label>imie</label>
- <input type="text" name='imie'/>
- <label>nazwisko</label>
- <input type="text" name='nazwisko' />
- <input type="submit" value='zapisz' />
- </form>
- <p class='lista'>
- </p>
- </body>
- </html>
- document.addEventListener('DOMContentLoaded',()=> {
- let form=document.querySelector('.dane')
- form.addEventListener('submit', e=> {
- e.preventDefault()
- let osoba={}
- osoba['imie']=form[0].value
- osoba['nazwisko']=form[1].value
- fetch('http://localhost/MTjs/ajax/nazwiska.php', {
- method:'POST',
- headers:{
- 'Content-type':'application/json; charset=UTF-8'
- },
- body: JSON.stringify(osoba)
- })
- .then(odp=>{
- return odp.json()
- })
- .then(odp=>{
- console.log(odp)
- let p=document.querySelector('.lista')
- p.textContent=odp
- })
- })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement