如何将Jquery函数中的数据get从超链接传递给servlet?

时间:2016-09-24 20:18:00

标签: jquery

$(document).ready(function(){
    alert("inside function");
    $(".month").click(function(e){
         alert("hii");
         $("a").click(function(){
             var m = $(this).attr("id") // or you can use this.id
             alert("current  selected month"+m);
             $.ajax({
                    type : "POST",
                    url : "Controller?action=month",
                    data : m,
                    success : function(data) {
                        alert("sucess");
                    }
              });
         });
     });              
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="bg1">
    <div class="bg2">
        <div class="main">
            <div class="box">
                <article id="content">			
                    <div class="box1">
                        <div class="wrapper">
                            <div class="h">
                                <div class="h1">					
                                    <ul class="month">					 
                                        <li><a class="month" id="01" href="#">January</a></li>
                                        <li><a class="month" id="02" href="#">February</a></li>
                                        <li><a class="month" id="03" href="#">March</a></li>
                                        <li><a class="month" id="04" href="#">April</a></li>                           
                                        <li><a class="month" id="05" href="#">May</a></li>
                                        <li><a class="month" id="06" href="#">June</a></li>
                                        <li><a class="month" id="07" href="#">July</a></li>
                                        <li><a class="month" id="08" href="#">August</a></li>
                                        <li><a class="month" id="09" href="#">September</a></li>
                                        <li><a class="month" id="10" href="#">October</a></li>
                                        <li><a class="month" id="11"href="#">November</a></li>
                                        <li><a class="month" id="12"href="#">December</a></li>
                                    </ul>				
                                </div>
                                <div class="h2">
                                    <div align="right">
                                        <a href="maintenance_table.tiles" class="button2">Show All</a>
                                    </div>
                                    <center>
                                        <h2>Maintenance Form</h2>
                                        <form id="mentainenceForm" action="#"method="post">

                                            <table>
                                                <tr class="wrapper">
                                                    <td>Date:</td>
                                                    <td><input type="text" class="input"></td>
                                                </tr>
                                                <tr>
                                                    <td>Electric :</td>
                                                    <td><input type="text" class="input"></td>
                                                </tr>
                                                <tr class="wrapper">
                                                    <td>Water :</td>
                                                    <td><input type="text" class="input"></td>
                                                </tr>
                                                <tr class="wrapper">
                                                    <td>Internet:</td>
                                                    <td><input type="text" class="input"></td>
                                                </tr>
                                                <tr class="wrapper">
                                                    <td>Maintenance:</td>
                                                    <td><input type="text" class="input"></td>
                                                </tr>
                                                <tr>
                                                    <td></td>
                                                    <td><a href="#" class="button2">Submit</a></td>
                                                </tr>
                                            </table>
                                        </form>
                                    </center>
                                </div>
                            </div>
                        </div>
                    </div>
                </article>
            </div>
        </div>
    </div>
</div>

我正在尝试获取月份id onclick of hyperlink.i在jquery功能中获取id但在获取id后我想在我的控制器中发送该ID以获取详细信息。所以请建议我可以在我的代码中更改所以该代码工作正常。

3 个答案:

答案 0 :(得分:0)

点击标签时,您需要首先阻止默认您的代码。

$(".month").click(function(e){
   e.preventDefault();

答案 1 :(得分:0)

您不需要内部点击监听器。将处理包含类array( 'post_type' => 'student', 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'meta_value', 'meta_key' => 'meta-order meta-last-name', ); 的元素的所有点击事件。

你纠正的js:

.month

答案 2 :(得分:-1)

您在代码中使用Jquery,因为我理解您必须包含jquery库。尝试将此代码包含在您的文件中,然后运行。

 SRC = “https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js” &GT;