Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Ajax请求在成功更新laravel时显示错误消息_Php_Ajax_Laravel - Fatal编程技术网

Php Ajax请求在成功更新laravel时显示错误消息

Php Ajax请求在成功更新laravel时显示错误消息,php,ajax,laravel,Php,Ajax,Laravel,在laravel更新表中,控制器的代码为: public function edit(){ $inputValue = [ 'id' => Input::get('id'), 'name' => Input::get('name'), 'parent_id' => Input::get('parent_id'), 'color' => Input::get('color'), 'des

laravel
更新表中,控制器的代码为:

public function edit(){
    $inputValue = [
        'id' => Input::get('id'),
        'name' => Input::get('name'),
        'parent_id' => Input::get('parent_id'),
        'color' => Input::get('color'),
        'description' => Input::get('notes')
    ];

    $validator = \Validator::make( $inputValue, \Resource::getEditFolderRules() );

    // Validate the input and return correct response
    if ($validator->fails()){
        return Response::json([
            'success' => false,
            'errors' => $validator->getMessageBag()->toArray()
        ]);
    }

    $resource = $this->repo->updateFolderBasicDetail($inputValue);
    return Response::json([
        'success' => true,
        'url' => \URL::route('folder-detail', $inputValue['id'])
    ]);
}
js是:

<script type="text/javascript">
    $(function(){
        $("#edit-folder").on('submit', function(e){
            e.preventDefault();
            if($("#edit-folder").valid() == true){
                var description = CKEDITOR.instances.edit_folder_ckeditor1.getData();
                $('#notes').val(description);
                $.ajax({
                    url: "{{ URL::to('folder/edit') }}",
                    type: "POST",
                    data: $( this ).serialize(),
                    dataType: "json",
                    success:function(data) {
                        var errorString = '<ul class="msg msg_unsuccess">';
                        var success = 'Folder is updated.';
                        errorString += '<li>' + success + '</li>';
                        errorString += '</ul>';
                        $('#sucessmsg').html(errorString).delay(3000).fadeOut();
                        $('.modal-content').delay(3000).fadeOut();
                        $('.fade').delay(3000).fadeOut();
                    },
                    error:function(data) {
                        var errorString = '<ul class="msg msg_success">';
                        var error = 'Folder is not updated.';
                        errorString += '<li>' + error + '</li>';
                        errorString += '</ul>';
                        $('#sucessmsg').html(errorString).delay(3000).fadeOut();
                        $('.modal-content').delay(3000).fadeOut();
                        $('.fade').delay(3000).fadeOut();
                        setTimeout(function(){location.reload();},3000);


                    }
                });
            }
        });

    });
</script>

$(函数(){
$(“#编辑文件夹”)。在('submit',函数(e){
e、 预防默认值();
if($(“#编辑文件夹”).valid()==true){
var description=CKEDITOR.instances.edit_folder_ckeditor1.getData();
$('注释').val(说明);
$.ajax({
url:“{{url::to('folder/edit')}}”,
类型:“POST”,
数据:$(this).serialize(),
数据类型:“json”,
成功:功能(数据){
var errorString='
    ; var success='文件夹已更新'; errorString+='
  • '+success+'
  • '; errorString+='
'; $('#sucesmsg').html(errorString).delay(3000).fadeOut(); $('.modal content').delay(3000.fadeOut(); $('.fade').delay(3000.fadeOut(); }, 错误:函数(数据){ var errorString='
    '; var error='文件夹未更新'; errorString+='
  • '+error+'
  • '; errorString+='
'; $('#sucesmsg').html(errorString).delay(3000).fadeOut(); $('.modal content').delay(3000.fadeOut(); $('.fade').delay(3000.fadeOut(); setTimeout(函数(){location.reload();},3000); } }); } }); });
但是,当我更新文件夹时,它正在更新,并且显示的消息来自
错误:function


不明白我错在哪里,请帮助我。

我在Laravel 5.2中使用AJAX,在包含脚本之前,在php文件中创建变量url和变量令牌(如果需要),在其中查看

<script>
    var token = '{{ Session::token()}}';
    var url = '{{ route('select_cafe') }}';
</script> 
<script src="{{asset('/script/select_cafe.js')}}" ></script>

var-token='{{Session::token()}}';
var url='{route('select_cafe')}}';

我在Laravel 5.2中使用AJAX,在包含脚本之前,在查看的php文件中创建了路由、变量url和变量令牌(如果需要)

<script>
    var token = '{{ Session::token()}}';
    var url = '{{ route('select_cafe') }}';
</script> 
<script src="{{asset('/script/select_cafe.js')}}" ></script>

var-token='{{Session::token()}}';
var url='{route('select_cafe')}}';

这不是问题所在,但为什么类
msg_success
success
函数中,类
msg_success
error
函数中…?我没有使用laravel,但是您确定您的服务器响应是一个
json
字符串吗?@ImClarky此类用于为消息提供背景颜色。您可能应该在
success
函数中处理文件夹是否已更新。
error
函数主要在ajax请求本身失败时使用。但是,即使文件夹详细信息更新了,也没有选择成功部分不是因为这是问题,而是为什么在
success
函数中的类
msg\u success
,以及在
error
函数中的类
msg\u success
,但是您确定您的服务器响应是一个
json
字符串吗?@ImClarky此类用于为消息提供背景颜色。您可能应该在
success
函数中处理文件夹是否已更新。
error
函数主要在ajax请求本身失败时使用。但即使更新了文件夹详细信息,它也不会选择成功部分