[ajax] post the data as json
<DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>TEST CATCH API</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
var Submit = function() {
var json = {
"userName": "test",
"msg": "test"
}
$.ajax({
url: 'http://test123/api/add',
/*
data: {
"name":"123",
"age":"50"
},
*/
data: JSON.stringify(json),
type: "POST",
dataType: 'text',
success: function(msg) {
// alert(msg);
console.log(msg)
},
error: function(xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
</script>
</head>
<body>
<form id="sentToBack">
<input type="text" name="Text" />
<input type="button" value="送出" onClick="Submit()" />
</form>
</body>
</html>
---
type: string $content: {"userName":"test","msg":"test"}
留言
張貼留言