[英]How to pass a link value from a HTML page to rest web service
If I have a HTML or a JSP page having list of sports like below. 如果我有一个HTML或JSP页面,其中包含如下所示的运动列表。
Tennis 网球
Football 足球
Hockey 曲棍球
Cricket 蟋蟀
All these 4 should be a Link. 所有这四个应该是一个链接。 If I click on any of them it should return some details wherever clicked. 如果我单击其中任何一个,则无论单击何处,都应返回一些详细信息。 For this I need to pass this sport name to a REST client which will pass this as a parameter to a rest service. 为此,我需要将此运动名称传递给REST客户端,该客户端会将其作为参数传递给rest服务。
My question is how to pass the value of a link whichever clicked from HTML page to a Java application like we pass text box or check box values from HTML using the form action? 我的问题是如何将链接页面的值传递给HTML应用程序中传递的HTML文本框或复选框值? Or is there any better approach, please suggest 还是有更好的方法,请提出建议
I suggest you to look at jQuery.ajax . 我建议您看看jQuery.ajax 。 Basically you'll want to create an XHR (GET, POST etc depending on the rest client configuration) and send your data. 基本上,您将要创建一个XHR(取决于其余客户端配置的GET,POST等)并发送数据。
Here is a very crude example on the subject; 这是关于这个主题的一个非常粗糙的例子。
$('.sports').on('click', function() {
var clickedElementText = $(this).text();
$.ajax({
url: "/your/endpoint/url",
method: "POST",
data: {
sportName : clickedElementText;
},
}).success(function( response ) {
/* success callback */
}).failure(function( jqXHR, textStatus ) {
/* failure callback */
});
}
Ajax是一种好方法,也可以只定义元素
<a href="/sports/detail?sportName=tennis">
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.