2015-01-15 13 views
0

新来laravel,在预制项目的工作是replicatinga到另一个部分中的功能,但现在我卡住了:

Failed to load resource: the server responded with a status of 404 (Not Found) (17:26:57:137 | error, network) at http://localhost/testimonials/sort 

的行动的地方作出的URL : http://localhost/ ***** /公/ index.php文件/管理/推荐

我有这样的一段JavaScript代码是被由事件称为:

sortTestimonials: function() { 
     $("#sortable_1, #sortable_2").sortable({connectWith: ".connectedSortable", stop: function() { 
       var t = []; 
       t = $(".connectedSortable").sortable("toArray"), 
       $.post("/testimonials/sort", {list: t}) 
      }}) 
    }, 

这$。员额(..)据说去我routes.php文件在那里我有控制器/段的路线

# Testimonials Routes 
    Route::resource('testimonials', 'AdminTestimonialsController', ['except' => ['show', 'destroy']]); 
    Route::post('testimonials/toggleVisibility', '[email protected]'); 
    Route::post('testimonials/delete', '[email protected]'); 
    Route::post('testimonials/sort', '[email protected]'); 
     //this last one being the one it's supposed to grab 

然后,我有我的控制器AdminTestimonialsController.php,我不能去(只是显示的问题明显)

public function sort() { 
     $order = Input::get('list'); 
     if (Request::ajax()) { 
         $result = $this->testimonial->sortArticles($order); 
     } 
     return Redirect::route('admin.testimonials.index'); 
    } 

那么我在做什么错在这里,或者我错过了它的工作?

+0

尝试在路由::资源前定义Route :: post路由 – lukasgeiter 2015-01-15 17:59:19

+0

@lukasgeiter没有区别 – 2015-01-15 18:06:38

回答

0

由于您的应用程序不在您的域的根目录中,因此您不能只使用/testimonials/sort。它将向http://localhost/testimonials/sort发出请求,而不是http://localhost/*****/public/index.php/testimonials/sort

您可以在您的PHP /刀片模板中的某处定义一个baseUrl js变量,并在您发出ajax请求时使用它。

<script> 
    var baseUrl = "{{ URL::to('/') }}"; 
</script> 

然后

$.post(baseUrl + "/testimonials/sort", {list: t}) 

注意,你仍然需要/在网址前面,因为baseUrl将不斜线。

+0

但是在那种情况下,它对于instante而言是如何工作的? (我以自己为基础,在网站的产品部分)$ .post(“products/sort”,{list:t}) – 2015-01-15 18:25:15

+0

您可以保留与您当前版本相关的URL。 – lukasgeiter 2015-01-15 18:26:17