0

我写了一个代码,当用户不执行任何活动时自动注销。但有一件事,我无法弄清楚。我希望当我从下拉列表中选择选项时,它将传递给 AJAX,您能否修改它,以便我可以将选项中的数据发送到 AJAX。

<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<style type="text/css">
#idletimeout { background:#CC5100; border:3px solid #FF6500; color:#fff; font-family:arial, sans-serif; text-align:center; font-size:12px; padding:10px; position:relative; top:0px; left:0; right:0; z-index:100000; display:none; }
#idletimeout a { color:#fff; font-weight:bold }
#idletimeout span { font-weight:bold }
</style>

</head>
<body>

<div id="idletimeout">
You will be logged off in <span><!-- countdown place holder --></span>&nbsp;seconds due to inactivity.
<a id="idletimeout-resume" href="#">Click here to continue using this web page</a> Please select reason for being idle.
<select id='idleReason' size="1">
<option value="nothing" selected="selected">Select a site</option>
<option value="Option 1">Option 1</option>
<option value="Option 2">Option 2</option>
<option value="Option 3">Option 3</option>
<option value="Option 4">Option 4</option>
</select>

</div>

Content Lorem Impsum

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
<script src="jquery.idletimer.js" type="text/javascript"></script>
<script src="jquery.idletimeout.js" type="text/javascript"></script>
<script type="text/javascript">
$.idleTimeout('#idletimeout', '#idletimeout a', {
        idleAfter: 3,
        pollingInterval: 2,
        keepAliveURL: 'keepalive.php',
        serverResponseEquals: 'OK',
        onTimeout: function(){
                $(this).slideUp();
                window.location = "timeout.htm";
        },
        onIdle: function(){
                $(this).slideDown(); // show the warning bar
        },
        onCountdown: function( counter ){
                $(this).find("span").html( counter ); // update the counter
        },
        onResume: function(){
                $(this).slideUp(); // hide the warning bar
        }
});
//
</script>


</body>
</html>

我会很感激你的。

4

1 回答 1

0

您的 jQuery 函数的基本形式应如下所示:

$('#idleReason').change(function(){
    $.ajax({
        url: 'http://www.your.ajax.handler'
        data: $('#idleReason option:selected').html()
    });
);

您应该查看ajax 文档以获取有关如何自定义查询的更多信息。

于 2012-05-04T08:17:43.823 回答