Laravel控制器无法使用jQuery

问题描述:

当在一个简单的Laravel 4测试应用创建视图当用户点击“上传”,jQuery的发送FORMDATA到控制器Laravel控制器无法使用jQuery

var formdata = new FormData(form); 
    request.open('post', 'submit'); 
    request.send(formdata); 

控制器接收文件并对阵列图片。

foreach(Input::file("image") as $image) { 

     $imagename = $image->getClientOriginalname(); 
     $uploadflag = $image->move('public/uploads', $imagename); 
     if($uploadflag){ 

      $uploadedImages[] = $imagename; 
     } 
    } 
return Response::json(['success' => true, 'message' => 'images uploaded successfully', 'images' => $uploadedImages]); 

现在我想在视图中显示(show.php)的图像,以便在控制器:

return View::make('show') 
        ->with('uploadedImages', $uploadedImages); 

show.php只包含一个循环:

@foreach($uploadedImages as $uploadedImage) 

     <div>{{ HTML::image($uploadedImage) }}</div> 

     @endforeach 

但没有任何反应 - 视图不显示。 Laravel日志文件中没有错误消息,Response :: json结果显示图像在数组中。 以下是我已经尝试了路线:

Route::post('show', function() 
{ 
    return View::make('show'); 
}); 

,我已经试过

Route::get('show', function() 
{ 
    return View::make('show'); 
}); 

,我已经试过

Route::post('show', array(
    'as' => 'show', 
    'uses' => '[email protected]' 
)); 

没有jQuery的,没有问题与控制器 - 返回View :: make - 但现在jQuery处理上传不起作用。我需要jQuery来允许用户对要上传的文件进行最终选择。 任何和所有的帮助,最欢迎!

如果你的输出文件只是“show.php”,它将不起作用,文件必须具有扩展名.blade,就像这个“show.blade.php”一样。

,不要忘了这个文件添加到您的“路线”了。

+0

嗨,我改成了show.blade.php,但并不路线::让您的视图文件( 'show',function(){return View :: make('show');));好?它仍然不起作用。 – metarzan 2014-12-06 21:45:17

+0

仅在输出结果前才返回视图 – 2014-12-07 04:09:51

+0

谢谢,但没有变化。响应头显示200 OK,Chrome Canary DevTools预览显示正确放置在页面上的图像细节,但页面无法加载。我想张贴一张图片来展示给你,但我需要首先获得10的声望。在我看来,如果图像在页面代码中,它必定是Laravel中我看不到的东西。 – metarzan 2014-12-08 02:38:24

使用字符串函数像以前一样为

return (String) view('Company.allUserAjax',$data) 

后个够将响应