【问题标题】:ajax is not returning response to view page in the applicationajax 没有返回响应以在应用程序中查看页面
【发布时间】:2016-06-25 07:55:07
【问题描述】:

当我在 Firefox 控制台窗口中调试时,我可以看到输出,但它没有出现在我的视图页面上,下面我提到了我的 ajax 代码和我的控制器,我得到了结果但视图没有显示

阿贾克斯:

<script>
$('.click').click(function(evt) {
 evt.preventDefault();
 var link = $(this).attr('id');
$.ajax({
   type: "GET",
   url: 'p_details',
   dataType: "json",

   data: {
      id: link   
 }
});
   //alert(data);
}).done(function(data) { // pass the url back to the client after you    incremented it
$('#property').empty('clear').html(data.html);
});
 </script>

控制器:

public function index()
{
       //$filter=Input::get('id');
       //var_dump($term);
        $view=DB::table('property_details')
     ->Where('sale_or_rent', '=', 'rent')
        ->orWhere('sale_or_rent', '=', 'sale')
       ->get();
     //  var_dump($view);
    return view::make('index', array('val'=>$view));
}

public function getPropertyDetails()
{
     $filter = Input::get('id');
    $display = DB::table('property_details')
              ->where('sale_or_rent', 'LIKE', '%' . $filter . '%')
              ->get();
              //var_dump($display); 

    if(count($display)!=0)
    {
        $returnHTML = view('/pages/fliter')->with('val', $display)->render();
        return response()->json(array('success' => true, 'html'=>$returnHTML));
    }
    else
    {
        session::flash('status', 'No Records Found!!!');
        $returnHTML = view('/pages/fliter')->with('val', $display)->render();
        return response()->json(array('success' => true, 'html'=>$returnHTML));
    }
}

【问题讨论】:

标签: javascript ajax laravel laravel-5 onclick


【解决方案1】:

应该

$('#property').empty('clear').html(row.html);

不是

$('#property').empty('clear').html(data.html);

.sucess() 也拼写错误。应该是.success()

【讨论】:

  • 嗨,我已根据您的建议修改了我的代码,但仍然无法正常工作,在我的控制台中,我收到了响应...我已经更新了上面的 ajax 检查
  • @VallavanJ 您已将完成功能添加到点击事件之后。它需要直接出现在 ajax 函数之后。
  • 在我的ajax调用之后已经添加了.done函数,请详细说明你在说什么..
  • 你写的是 $('.click').click(function() {}).done() 而不是 $.ajax().done()。您应该始终正确缩进您的代码。它有助于阻止此类错误。
  • 你可以建议我可以在 mycode 上实现的东西,但视图不应该能够响应我的 page.in alert(html.data) 我看到 html 视图但我没有得到确切的解决方案..plzz提出一些建议..
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-26
  • 1970-01-01
  • 2018-05-16
  • 2015-01-02
  • 2015-11-09
  • 2018-01-14
相关资源
最近更新 更多