<form id="participantsForGd">
<span id="GroupID"></span> //in here group id is coming example: 2
<button id="GdStartTest">Start test</button>
</form>
我想使用 Ajax 调用将 GroupID 的值发送到 Controller ,我该怎么做。? 这是我的追加 java 脚本..
$("#GroupID").append( group ); //in here Example: group value=2
这是我的 Controller 页面调用:
$("#GdStartTest").click(function(){
$.ajax({
data: {Gd: $("#participantsForGd").serialize(), 'action': 'startGdstudents', },
我想在 Ajax data:
或 input type=hidden
表单中添加该组 ID。我该怎么做
最佳答案
$("#GdStartTest").click(function(){
$.ajax({
data: {Gd: "sometext-"+ $("#GroupID").text(), 'action': 'startGdstudents', }
".text()":将返回元素的内容。
如果你想创建隐藏的输入,你可以这样做:
$("#groupID").val(); // this will return you the value
$("#GdStartTest").click(function(){
$.ajax({
data: {Gd: "sometext-"+ $("#GroupID").val(), 'action': 'startGdstudents', }
关于javascript - 我如何将动态附加值发送到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41421510/