POST localhost:5000/registrar
{
"enrollId": "jim",
"enrollSecret": "6avZQLwcUe9b"
}
如何在 javascript 文件中使用它?我使用 JSON 还是 JQuery?如何调用.html中的请求函数?
为此使用 jquery:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
并调用函数
$(document).ready(function(){
$.post('localhost:5000/registrar', {
"enrollId": "jim",
"enrollSecret": "6avZQLwcUe9b"
}, function(serverResponse){
//do what you want with server response
})
})
相同,没有处理错误的简写:
$.ajax({
type: "POST",
url: 'localhost:5000/registrar',
data: {
"enrollId": "jim",
"enrollSecret": "6avZQLwcUe9b"
},
success: function(){$('#register').html('<h1>Login successfull</h1>');},
error: function(){$('#register').html('<h1>Login error</h1>');},
dataType: dataType
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)