douliangli6407 2015-05-15 08:04
浏览 93

Ajax请求不使用PHP

I'm Having 2 select in my form which one will have the Main Villages and the second one has to show the small villages in depending on the main village selected.

Here is the AJAX request.

<script>
  $('#GN_Number').change(function()
  {
    alert('changed');
    $.get('/GN_Number/' + this.value + '/villages.json', function(villages)
    {
       var $state = $('#Village_ID');
       $state.find('option').remove().end();
       $.each(villages, function(index, village) 
       {
          $state.append('<option value="' + village.id + '">' 
                                +village.Tamil + '</option>');
       });
    });
});

And the HTML Code

<tr>
<td>
    @if($gn != null)
      <select id="GN_Number" class="selector" name="GN_Number">
        <option value=""></option>
        @foreach($gn as $n)
          <option value="{{ $n->id }}">{{ $n->Tamil }}</option>
        @endforeach
      </select>
   @endif
</td>

<td>
<select id="Village_ID" class="selector" name="Village_ID">
 </select>
 </td>

And the route I have for the Request is as follows

get('GN_Number/{code}/villages.json', function($code)
{

    return village_list::where('GN_ID', $code)->get();
});

While I'm testing the code in Chrome Developer mode I don't find any ajax request being made.

Please Check this code and correct me if I'm wrong

Thanks in advance

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 AT89C51控制8位八段数码管显示时钟。
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口