weixin_33735077 2014-07-16 12:50 采纳率: 0%
浏览 125

JSP不调用Ajax函数

I have written an ajax function which will be called when someone selects a year from a dropdown. On selecting the year, the ajax will call a servlet based on passed URL and that servlet will set a value in properties file. However, the problem is, on selecting the year, my ajax block is not called

</tr>
                    <tr>
                    <td>Year</td>
                    <td>
                        <html:select property="yearId" >
                            <html:options collection=
                                    "<%=GlobalValues.LIST_MODELYEAR%>" 
                                    property="id" labelProperty="value" />
                        </html:select>
                        (Required)
                    </td>
                </tr>

                <script>
        $(document).ready(function() 
        {
            $("#yearId").change(function() 
            {

                var selectedValue = $(this).find(":selected").val();
                $.ajax

                ({
                    url : "/ModelByYear.do?cID="+selectedValue+'',



                });
            });
        });
        </script>   
  • 写回答

2条回答 默认 最新

  • weixin_33747129 2014-07-16 13:10
    关注

    Remove the / from your URL as given below and the , is not neccesory

    $.ajax({
             url : "ModelByYear.do?cID="+selectedValue
          });
    

    Try by using the below code

    $.ajax({
      type: "GET",
      url: "ModelByYear.do",
      data: {cID:selectedValue},
      success: function(result){
                  alert('Result: ' + result);
               },
       error: function(err){
                   alert('Error: ' + e);     
              }
         });
    
    • type is html request type you can use GET or POST
    • ModelByYear.do is URL in you case you must map this url-pattern in WEB.xml

    While working on JSP's don't call jsp pages directly instead configure in WEB.xml as given here

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度