如何在asp.net中发送jQuery变量值到服务器端
how can send a jQuery variable value to server side in asp.net
这是我的jQuery:
$(document).ready(function () {
var image = $('#man');
var legTooltip = 'LEG';
image.mapster({
fillOpacity: 0.5,
mapKey: 'alt',
fillColor: "000000",
listKey: 'alt',
scaleMap: falsee,
singleSelect: true,
toolTipClose: ["tooltip-click", "area-click", "area-mouseout"],
showToolTip: true,
onClick: function (e) {
if (e.key === 'leg') {
var **symp** = e.key;
}
},
areas: [
{
key: "leg",
toolTip: legTooltip
}],
render_highlight: {
fade: false
}
});
});
现在我如何将变量symp的值发送到服务器端cs文件并将值保存到另一个服务器端变量?我对jquery和asp.net知之甚少。
如果我理解对了,你需要发送一个post请求到服务器。您可以通过使用jQuery方法post(这是一个简短的Ajax函数)来实现。
$.post(
"YourController/YourMethod",
{ symp },
function( response ) {
//proccess the response here
}
);
在服务器端,在控制器中添加一个方法来获取
public class YourController : Controller
{
//other methods and fields
[HttpPost]
public ActionResult YourMethod(<type of variable symp> symp)
{
//save this value wherever you want
//return result of your request, so you can proccess it on the client side
//e.g. that operation was successfully completed
}
}
试试ajax:
$.(ajax){(
url : 'url of the file in which yo want to process the data',
method: 'post or get',
data: {
var1 : value1,
var2 : value2
// these variables are available on the specified url
// use your variable(symp) here
},
success: function(response)
{
// response hold the server side response in it.
}
)}
不要忘记在你的代码中包含jquery库
如果symp
的值需要不断更新,那么Ajax会更好,正如Mayank Pandeys的回答。但是如果你只需要PostBack的值,一个HiddenField将是最简单的。
<asp:HiddenField ID="HiddenField1" runat="server" />
if (e.key === 'leg') {
var **symp** = e.key;
document.getElementById("<%= HiddenField1.ClientID %>").value = symp;
}
然后你可以在后面的代码中使用symp
的值,通过从HiddenField获取值。
string symp = HiddenField1.Value;
相关文章:
- jQuery UI对话框窗体-缺少变量值
- jquery没有't从DIV数据id中获取PHP变量值,只输出变量名
- jQuery:从点击事件传递变量值失败
- 在jQuery上发出ajax请求后,闭包在获取变量值方面似乎迟到了
- 从函数jquery获取更新的变量值
- 如何在 jQuery 中的函数之外使用变量值
- 使用 jQuery 从其他 JavaScript 文件设置变量值
- JQuery 更改函数外部的变量值
- 在 jquery 函数中获取变量值为无穷大
- 如何将变量值从 php 发送到 jquery
- 如何在 PHP 数组中传递 JavaScript jQuery 变量值
- Jquery/Javascript - 变量正在接受另一个变量值
- Jquery变量值出血
- 如何发送或分配Jquery变量值给php变量
- 如何在asp.net中发送jQuery变量值到服务器端
- jQuery变量值没有得到
- 我如何得到jquery变量值被PHP $_POST读取
- POST(或GET) JavaScript (jQuery)变量值到php
- JQuery变量值加引号
- 在多次回发中保留一个JQuery变量值