2014-06-20 37 views
0

我來自Codeigniter的Laravel 4.x &不明白Laravel的錯誤信息。我試圖加載視圖到視圖,這是我的代碼Laravel:通過ajax加載視圖到一個視圖

路線

Route::get('widget/addcustomer', '[email protected]'); 

控制器

public function addcustomer() 
{ 
    return View::make('widget.addcustomer')->render(); 
} 

主要view.blade.php

<script> 
function loadwidget(1, 'formname', 1) 
{ 
    var widget_url = '<?php echo URL::to('widget'); ?>'; 

    $.ajax({ 
     type:'POST', 
     url: widget_url+'/'+formname, 
     dataType: "html", 
     async: false, 
     cache: false, 
     success: function(response) 
     { 
      $('#'+divid).html(response); 

      if(active==0) 
      {    
       $('#'+divid+' :input').attr('disabled', true);    
      }  
     } 
    }); 
    return true; 
} 
</script> 

外部view.php

<form id="customer_form"> 
    <table><tr><td>....</td></tr></table> 
</form> 

但火災的錯誤我得到

{"error":{"type":"Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException","message":"","file":"E:\\xampp\\htdocs\\tt_kickoff\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RouteCollection.php","line":210}} 

,如果我打http://localhost/tt_kickoff/widget/addcustomer 它加載正確的HTML

+0

發表您的routes文件 – Laurence

+0

路線:路線::獲得( '工具/ addcustomer', 'WidgetController @ addcustomer'); –

回答

2

你的路由文件將有GET方法addcustomer() - 但您是「發佈」的路線,所以你還需要一個POST方法。

編輯:

所以你改變

Route::get('widget/addcustomer', '[email protected]'); 

Route::post('widget/addcustomer', '[email protected]'); 

改變你的Ajax

type:'POST', 

type:'GET', 
+0

完美的感謝:D –

+0

什麼是「divid」 - 我沒有看到在任何地方定義?無論如何 - 這解決了你的路線問題 - 現在你有一個Ajax問題.... – Laurence

相關問題