简体   繁体   English

如何将链接值从HTML页面传递到Rest Web服务

[英]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.

相关问题 如何从 html 获取文本字段值并将其传递给 REST GET 服务并在动态 HTML 表中显示响应 - How to get text field value from html and pass it to REST GET service and display the response in dynamic HTML table 如何将参数从prototypejs客户端传递到REST Web服务 - How to pass parameter from prototypejs client to rest web service 如何在angular js中使用rest web服务响应的html值 - How to consume html value of rest web service response in angular js 如何从Java Rest Web服务返回ajax中的值? - How to return a value in ajax from a Java Rest Web service? 如何将数值从链接传递到同一页面上的脚本 - How to pass numeric value from a link to a script on the same page 如何将pojo对象作为参数传递给prototypejs客户端的其余Web服务 - How to pass pojo object as parameter to rest web service from prototypejs client 如何在JavaScript中将值从一个html页面传递到另一个页面? - How to pass value from one html page to another in JavaScript? 如何将文本框值从一个html页面传递到另一个 - How to pass a text box value from one html page to another 如何在同一页面中将动态值从脚本传递到HTML? - how To Pass A Dynamic Value from Script to HTML In the Same Page? 无法使用参数从html / javascript调用rest Web服务 - unable to call rest web service from html/javascript with parameter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM