Logging update, Trying to get JS post to work
This commit is contained in:
parent
3ec04c090d
commit
1716443bf9
7 changed files with 642 additions and 3 deletions
|
|
@ -87,6 +87,59 @@
|
|||
}
|
||||
}
|
||||
alert("Tauschen:\n"+selected_players.join("\n"));
|
||||
|
||||
xmlhttp=new XMLHttpRequest()
|
||||
|
||||
var formData=new FormData()
|
||||
//alert(inputElems[0].id);
|
||||
formData.append('user1',inputElems[0].id)
|
||||
formData.append('user2',inputElems[1].id)
|
||||
|
||||
|
||||
let params="user1=test&user2=test2"
|
||||
|
||||
xmlhttp.open("POST",'/league/swap')
|
||||
xmlhttp.setRequestHeader('Content-Type', 'application/json')
|
||||
xmlhttp.setRequestHeader('X-CSRF-Token', '{{ csrf_token() }}')
|
||||
|
||||
//xmlhttp.send(params)
|
||||
|
||||
xmlhttp.send(formData)
|
||||
|
||||
return;
|
||||
// For POST, we need a configuration object for the fetch call
|
||||
const update = {
|
||||
title: 'A blog post by Kingsley',
|
||||
body: 'Brilliant post on fetch API',
|
||||
userId: 1,
|
||||
};
|
||||
|
||||
console.log("Before stringify")
|
||||
const options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-CSRF-Token': '{{ csrf_token() }}'
|
||||
},
|
||||
body: JSON.stringify(update),
|
||||
};
|
||||
console.log(JSON.stringify(update))
|
||||
console.log("After stringify")
|
||||
|
||||
fetch('/league/swap', options)
|
||||
.then(data => {
|
||||
if (!data.ok) {
|
||||
throw Error(data.status);
|
||||
}
|
||||
return data.json();
|
||||
}).then(update => {
|
||||
console.log(update);
|
||||
}).catch(e => {
|
||||
console.log("There is some error")
|
||||
alert(e)
|
||||
console.log(e);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
<div class="lead">{{ $game->team1 }} : {{ $game->team2 }}</div>
|
||||
|
||||
<div >
|
||||
<div>
|
||||
<form method="POST" action="/tipps/store">
|
||||
{{ csrf_field() }}
|
||||
<div class="form-group">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue