我使用laravel 5.2开发web应用程序,我尝试将带有ajax的数组发送到我的控制器,请求已发送但在此之后我看到错误:405方法不允许,我搜索了很多次但是这个问题并没有。解决: 我的ajax代码是:
// send array of stream checkbox to controller
$('#json-btn').click(function () {
var input = $("form input:checkbox");
var stream = [];
$.each($(input), function(){
stream.push($(this).val());
});
var jstream = JSON.stringify(stream);
var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
$.ajax({
url: '/ajaxGet/',
type: 'POST',
data: {_token: CSRF_TOKEN , jstream:jstream},
dataType: 'JSON',
success: function (data) {
alert(data);
}
});
});
我的路线是:
Route::post('ajaxGet', 'ajaxController@getRequest');
我的控制器是:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class ajaxController extends Controller
{
public function getRequest(Request $request)
{
echo $request['jstream'];
}
}
最后这是我的表格:
{!! Form::open(array('id' => 'trailer-form')) !!}
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<table dir="rtl">
<thead>
<tr>
<th>quality</th>
<th>link</th>
<th>steram</th>
</tr>
</thead>
<tbody>
<tr>
<td>
{!! Form::select('quality[]', array('noQuality'=>'select...','64p'=>'64p','144p'=>'144p','240p'=>'240p','360p'=>'360p','480p'=>'480p','720p'=>'720p', '1080p'=>'1080p'), null , ['class'=> 'form-control lns' , 'id' => 'quality-input']) !!}
</td>
<td>
{!! Form::text('downLoadLink[]',null,['class' => 'form-control ln' , 'id' => 'down-input']) !!}
</td>
<td>
{!! Form::checkbox('stream[]','false',null,['class' => 'form-control' , 'id' => 'streamCheck' , 'onchange' => 'createAlerts(this)']) !!}
</td>
<td>
<button class="btn btn-success btn-add" type="button">
<i class="glyphicon glyphicon-plus gs"></i>
</button>
</td>
</tr>
</tbody>
</table>
{!! Form::submit('json create',['class' => 'btn btn-success' , 'id' => 'json-btn']) !!}
{!! Form::close() !!}
请帮我解决这个问题非常感谢你:)