admin管理员组文章数量:1297025
I want to call a servlet in JavaScript, but how to call I do not know.
function func_search()
{
var srchdata = document.getElementById('searchitem').value;
if(srchdata == "")
{
alert("Enter Search Criteria...");
}
else
{
//what to write here to call servlet ??
}
}
<a onclick="func_search();"><img src="images/srch.png" height="32px" width="32px"/></a>
I want to call a servlet in JavaScript, but how to call I do not know.
function func_search()
{
var srchdata = document.getElementById('searchitem').value;
if(srchdata == "")
{
alert("Enter Search Criteria...");
}
else
{
//what to write here to call servlet ??
}
}
<a onclick="func_search();"><img src="images/srch.png" height="32px" width="32px"/></a>
Share
Improve this question
edited Dec 18, 2013 at 13:22
Andrei Nicusan
4,6231 gold badge27 silver badges37 bronze badges
asked Dec 18, 2013 at 13:14
user2293418user2293418
1
- The terminology is 'navigation', not 'calling'. You call a method, you navigate to a web resource (or rather: you make the browser do it). I say so because using proper terminology will provide you with more relevant Google search results in the future. – Gimby Commented Dec 18, 2013 at 13:19
3 Answers
Reset to default 4document.location.href
is used
function func_search()
{
var srchdata = document.getElementById('searchitem').value;
//alert(srchdata);
if(srchdata == "")
{
alert("Enter Search Criteria...");
}
else
{
document.location.href="your servlet name here";
}
}
Servlets are mapped to URL pattern, so just need to make a call to that url (post/get/ ...) Create a an ajax request object and make a call. explore on JavaScript ajax methodologies.
http://www.w3schools./ajax/ajax_xmlhttprequest_send.asp
function callServlet()
{
document.getElementById("adminForm").action="./Administrator";
document.getElementById("adminForm").method = "GET";
document.getElementById("adminForm").submit();
}
<button type="submit" onclick="callServlet()" align="center">Register</button>
This way you can do it !!!
本文标签: javahow to call servlet in JavaScriptStack Overflow
版权声明:本文标题:java - how to call servlet in JavaScript? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741649064a2390362.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论