如何从JavaScript调用REST Web服务API? [英] How to call a REST web service API from JavaScript?
本文介绍了如何从JavaScript调用REST Web服务API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有按钮的HTML页面。当我点击那个按钮时,我需要调用Rest Web Service API?我试着在网上搜索。没有任何线索。有人可以给我一个带头人/ Headstart吗?非常感谢
I have a HTML page with a button on it. When I click on that button, I need to call a Rest Web Service API? I tried searching online everywhere. No clue whatsoever. Can someone give me a lead/Headstart on this? Very much appreciated
推荐答案
您的Javascript:
Your Javascript:
function UserAction() {
var xhttp = new XMLHttpRequest();
xhttp.open("POST", "Your Rest URL Here", true);
xhttp.setRequestHeader("Content-type", "application/json");
xhttp.send();
var response = JSON.parse(xhttp.responseText);
}
您的按钮操作::
Your Button action::
<button type="submit" onclick="UserAction()">Search</button>
欲了解更多信息,请浏览以下 link (2017/01/11更新)
For more info go through the following link (Updated 2017/01/11)
这篇关于如何从JavaScript调用REST Web服务API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文