@RequestMapping(value = "/adminNewClient", method = RequestMethod.DELETE)
public @ResponseBody Map adminNewClientPost(HttpServletResponse response, HttpServletRequest request,
@RequestParam(value = "name") String name,
@RequestParam(value = "surName") String secondName,
@RequestParam(value = "birthday") String birthdayDate,
@RequestParam(value = "passport") String passport,
@RequestParam(value = "adress") String adress,
@RequestParam(value = "email") String eMail,
@RequestParam(value = "number") String number) {
LinkedHashMap result = new LinkedHashMap();
result.put("nameStat","YES!");
return result;
}
<tr>
<td><input id="surName" type="text" class="form-control" placeholder="Surname"></td>
<td><span style="color:blue;" id="nameStat">${nameStat}</span></td>
</tr>
function popBox() {
x = confirm('Are you sure? ');
if (x == true) {
var xhr = new XMLHttpRequest();
xhr.onload = function(){
var jsonResponse = JSON.parse(this.responseText);
for(var index in jsonResponse) {
if (jsonResponse.hasOwnProperty(index)) {
document.getElementById(index).innerText = jsonResponse[index];
}
}
};
xhr.open("DELETE", "adminNewClient?name=" + name + "&surName=" + surName
+ "&birthday=" + birthday + "&passport=" + passport
+ "&adress=" + adress + "&email=" + email + "&number=" + number, false);
xhr.send();
}
}
for (let i = 0; i < 10; i++) {
setTimeout(function () {
console.log(i); // ?
}, 0);
}
var a = new Date().getTime();
var div = document.createElement('div');
div.innerHTML = 'Привет, мир!';
div.id = "removeMe"
document.body.appendChild(div);
console.log(new Date().getTime() - a); // миллисекунды затраченные на добавление элемента в DOM
window.setTimeout(function(){document.getElementById("removeMe");},200) // удаление элемента с задержкой на слуйчай если браузер подтупливает
return ResponseEntity.status(530).body(null);
@RequestMapping(value = "/admin",method = RequestMethod.DELETE)
public @ResponseBody String responseTest(HttpServletResponse response, HttpServletRequest request
) throws ResourceNotFoundException {
response.addHeader("Access-Control-Allow-Origin", "*");
response.addHeader("X-XSS-Protection", "0");
response.setStatus(530);
return "";
}
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
<html>
<head>
<title>TEST</title>
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
</head>
<body>
<form id="reg">
<input type="submit"/>
</form>
<div id="select_div"><a href="#" id="select_link">Send test data</a></div>
<script type="text/javascript">
$(function(){
$('#select_link').click(function(e){
e.preventDefault();
console.log('Send test data');
var data = {
name: "Виктор",
surname: "Цой"
};
$.ajax({
type: 'POST',
data: JSON.stringify(data),
contentType: 'application/json',
url: '/reg',
success: function(data) {
console.log('success');
console.log(JSON.stringify(data));
}
});
});
});
var form = document.querySelector('#reg');
form.addEventListener('submit', event => {
console.log('Form submited');
event.preventDefault();
var json = JSON.stringify({
name: "Виктор",
surname: "Цой"
});
var xhr = new XMLHttpRequest();
xhr.open('POST', '/reg');
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
xhr.send(json);
});
</script>
</body>
</html>
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser());
app.post('/reg', function(req, res){
console.log('body: ' + JSON.stringify(req.body));
res.send(req.body);
});
app.get('/', function(req, res) {
res.sendfile('views/test.html', {root: __dirname })
});
app.listen(10240);
{
"name": "testapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.14.0",
"body-parser": "1.8"
}
}
$.ajax({
type: "GET",
url: link,
crossDomain: true,
contentType: "application/json; charset=utf-8",
data: {},
dataType: "jsonp",
success: function(data){
console.log(data)
}
});