Laravel 4.2和AJAX POST - 500内部服务器错误 [英] Laravel 4.2 and AJAX POST - 500 Internal Server Error

查看:212
本文介绍了Laravel 4.2和AJAX POST - 500内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对下面的问题困惑:

我有一个code,看起来像这样

 <形式的行动={{网址::航线('用户发送消息')}}方法=后ID =形式,用户发送 - 消息>

@if($ user_message_block)
    <输入ID =MSG-IDNAME =MSG-id类型=隐藏值={{$ user_message_block-> ID}}>
@其他
    <输入ID =MSG-IDNAME =MSG-id类型=隐藏值=0>
@endif

    <输入ID =消气NAME =吸气式=隐藏值={{$简介 - >用户自>用户名}}>
    < textarea的ID =用户信息NAME =用户信息>< / textarea的>
    <按钮类=BTN BTN-成功BTN-XS右拉式类型=提交名称=BTN-发送消息>发送和LT; /按钮>
    < D​​IV CLASS =clearfix>< / DIV>
{{表格::令牌()}}
< /形式GT;

<脚本类型=文/ JavaScript的>
    jQuery的(文件)。就绪(函数($){
        $('#表单的用户发送消息)。在('提交',函数(){
           // ajax的POST方法
            $。员额(
                $(本).prop(行动),{
                    _token:$(本).find('输入[名称= _token]').VAL()
                    MSG-ID:$('#MSG-ID).VAL()
                    吸气剂:$('#getter').VAL()
                    用户信息:$('#用户信息).VAL()
                },
                功能(数据){
                    $(信息区)追加('< D​​IV CLASS =邮件用户>'+数据['谁'] +说:< / DIV>
                        +'< D​​IV CLASS =消息派> +数据['当'] +'< / DIV>
                        +'< D​​IV CLASS =消息看作>< EM> +数据['看到'] +'< / EM>< / DIV>
                        +'< D​​IV CLASS =clearfix>< / DIV>
                        +'< D​​IV CLASS =消息文本看到,没有> +数据['文本'] +'< / DIV>');
                    ('。消息区域)。$ scrollTop的($()[0] .scrollHeight'消息区。');
                    $('#用户信息)VAL('');
                },
                JSON
            );
            返回false;
        });
    });
< / SCRIPT>
 

当我删除了code这部分

  @if($ user_message_block)
    <输入ID =MSG-IDNAME =MSG-id类型=隐藏值={{$ user_message_block-> ID}}>
@其他
    <输入ID =MSG-IDNAME =MSG-id类型=隐藏值=0>
@endif
 

和我这个更换

 <输入ID =MSG-IDNAME =MSG-id类型=隐藏值={{$ user_message_block-> ID}}>
 

一切都工作得很好。

有什么关于如果其他条件会影响AJAX产生500错误。在HTML呈现正确,,

可有人或许不拼图这对我来说。

谢谢!

这是我的网络错误preVIEW

 错误:{类型:Symfony的\分量\调试\异常\ FatalErrorException,...}
文件:F:\ BOL \程序\控制器\ ProfileController.php
行:384
消息:调用一个成员函数count()在一个非对象
类型:Symfony的\分量\调试\异常\ FatalErrorException
 

解决方案

转到调试工具 - >网络 - >单击红色500内部服务器错误,和编辑您的OP与preVIEW(如果在Chrome )。

I am puzzled by the following problem:

I have a code that looks like this

<form action="{{ URL::route('user-send-message') }}" method="post" id="form-user-send-message">

@if( $user_message_block )
    <input id="msg-id" name="msg-id" type="hidden" value="{{ $user_message_block->id }}">
@else
    <input id="msg-id" name="msg-id" type="hidden" value="0">
@endif

    <input id="getter" name="getter" type="hidden" value="{{ $profile->user->username }}">
    <textarea id="user-message" name="user-message"></textarea>
    <button class="btn btn-success btn-xs pull-right" type="submit" name="btn-send-message">Send</button>
    <div class="clearfix"></div>
{{ Form::token() }}
</form>

<script type="text/javascript">
    jQuery(document).ready(function($){
        $('#form-user-send-message').on('submit', function(){          
           // ajax post method
            $.post(
                $(this).prop('action'),{
                    "_token": $( this ).find( 'input[name=_token]' ).val(),
                    "msg-id": $( '#msg-id' ).val(),
                    "getter": $( '#getter' ).val(),
                    "user-message": $( '#user-message' ).val()
                },
                function(data){
                    $(".message-area").append('<div class="message-user">' + data['who'] + ' said:</div>'
                        +'<div class="message-sent">' + data['when'] + '</div>'
                        +'<div class="message-viewed"><em>' + data['seen'] + '</em></div>'
                        +'<div class="clearfix"></div>'
                        +'<div class="message-text seen-no">' + data['text'] + '</div>');
                    $('.message-area').scrollTop($('.message-area')[0].scrollHeight);
                    $('#user-message').val('');
                },
                'json'
            ); 
            return false;
        }); 
    });
</script>

When I remove this portion of code

@if( $user_message_block )
    <input id="msg-id" name="msg-id" type="hidden" value="{{ $user_message_block->id }}">
@else
    <input id="msg-id" name="msg-id" type="hidden" value="0">
@endif

and I replace it with this

<input id="msg-id" name="msg-id" type="hidden" value="{{ $user_message_block->id }}">

everything works just fine.

Is there something about the If-else condition that would affect AJAX to produce 500 error. The HTML renders correctly,,

Can someone maybe un-puzzle this for me.

Thanks!

This is my network error preview

error: {type:Symfony\Component\Debug\Exception\FatalErrorException,…}
file: "F:\bol\app\controllers\ProfileController.php"
line: 384
message: "Call to a member function count() on a non-object"
type: "Symfony\Component\Debug\Exception\FatalErrorException"

解决方案

Go to debug tools -> network -> click the red 500 internal server error, and edit your OP with the "preview" (if on chrome).

这篇关于Laravel 4.2和AJAX POST - 500内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆