51 lines
1.6 KiB
Twig
51 lines
1.6 KiB
Twig
|
<div class="main-screen">
|
||
|
<div id="welcome" class="jumbotron">
|
||
|
<h1>
|
||
|
<span>Welcome to</span>
|
||
|
Symfony {{ constant('Symfony\\Component\\HttpKernel\\Kernel::VERSION') }}
|
||
|
</h1>
|
||
|
<div class="ajax-test">
|
||
|
<button class="btn btn-primary" onclick="testAjax( '{{ path('test_ajax') }}' )">test ajax</button>
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<script>
|
||
|
|
||
|
function makeRequest(method, url) {
|
||
|
return new Promise(function (resolve, reject) {
|
||
|
var xhr = new XMLHttpRequest();
|
||
|
xhr.open(method, url);
|
||
|
var payload = {stuff: ['one', 'two', 'three'], other: "hah"};
|
||
|
xhr.send(payload);
|
||
|
xhr.onload = function () {
|
||
|
if (this.status >= 200 && this.status < 300) {
|
||
|
resolve(xhr.response);
|
||
|
} else {
|
||
|
reject({
|
||
|
status : this.status,
|
||
|
statusText: xhr.statusText
|
||
|
});
|
||
|
}
|
||
|
};
|
||
|
xhr.onerror = function () {
|
||
|
reject({
|
||
|
status : this.status,
|
||
|
statusText: xhr.statusText
|
||
|
});
|
||
|
};
|
||
|
xhr.send();
|
||
|
});
|
||
|
}
|
||
|
|
||
|
var testAjax = function (url) {
|
||
|
console.log('test ajax');
|
||
|
makeRequest('POST', url)
|
||
|
.then(function (datums) {
|
||
|
console.log(datums);
|
||
|
})
|
||
|
.catch(function (err) {
|
||
|
console.error('Augh, there was an error!', err.statusText);
|
||
|
});
|
||
|
};
|
||
|
</script>
|