javascript - Using jquery Ajax in Laravel 4 -


i newbie ajax jquery , trying understand code , trying implement it. let know want , doing.

i have search box input "sku" , tables , information of particular sku.

i have in routes.php

route::get('bestsellers', array('as'=>'bestsellers', 'uses' =>'salesflatorderitemscontroller@index')); 

in controllers have

class salesflatorderitemscontroller extends \basecontroller { $sku_query = input::get('sku');          if($sku_query){         $orders = salesflatorder::join('sales_flat_order_item i','sales_flat_order.entity_id','=','i.order_id')                          ->select((array(db::raw('date(i.created_at) days'), db::raw('sum(i.qty_ordered) qty_ordered'), db::raw('sum(i.row_total) row_total'),'i.item_id', 'i.name','i.sku')))                          ->where('i.sku','=',$sku_query)                          ->groupby('i.sku')                          ->orderby('qty_ordered','desc')                          ->paginate(10);      }      return view::make('sales_flat_order_items.bestsellers')->with('orders', $orders); } 

and in bestsellers.blade.php , have

<input type="text" id="sku" placeholder="search sku..." name="sku"> <input type="hidden" id="search_sku" name="search_sku" value="">  <button type="button" id="searchsubmit" class="btn btn-info">search</button><div class="spin-area" id="spin-area">  <thead>        <tr class="odd gradex">          <th>sku</th>       <th>product name</th>       <th>items ordered</th>       <th>total</th>          </thead>    @foreach ($orders $item )     <tr class="odd gradex">      <td><a href="{{ url::action('salesflatorderitemscontroller@performance', $item->sku) }}">{{ $item->sku  }}</a></td>     <td>{{ $item->name }}</td>     <td>{{ round( $item->qty_ordered,2) }}</td>     <td>{{ round( $item->row_total,2) }}</td>   </tr>  @endforeach </table> </div> </div> </div> </div> 

this input sku should entered , ajax should information of sku on same page. ajax below

<script> $(document).ready(function(){      $('#searchsubmit').on('click',function(){       var data ="sku="+$('#sku').val();        $.ajax({         type:"get",         data:data,         url:"/bestsellers",         datatype:"json",         success:function(data){           alert('success');         }        })     });   });  </script> 

can let me know going wrong code, before have used traditional way of post , request, works, not ajax call.
please help.
thanks.

try

$(document).on('click','#searchsubmit',function(){     var data ="sku="+$('#sku').val();     $.ajax({         type:"get",         data:data,         url:"{{url::to('/bestsellers')}}",         datatype:"json",         success:function(data){             alert('success');             // data variable have data returned server. use show response         }     }) }); 

Comments

Popular posts from this blog

c++ - OpenMP unpredictable overhead -

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

javascript - Wordpress slider, not displayed 100% width -