2016-11-16 6 views
0

で始まるLaravel 5.2 JSONレスポンスいつかいくつかの時間応答は私だけでユーザーとの対話 JSON応答で、クライアント側のエラー作るJSONレスポンスをリードする0で始まるように私はlaravel 5.2 JSONレスポンス<br> に次のような問題を持っているゼロ

0{"message":"now shall be readed at least in javascript","fromuser":7,"fromShopid":null,"to_shop_id":9,"to_user_id":null,"status":0,"updated_at":"2016-11-16 14:20:45","created_at":"2016-11-16 14:20:45","id":58,"Created":1479295245,"shopName":"\u041a\u043e\u0440\u0430\u0431\u043b\u0438\u043a","shopLogo":"logo1475487308.jpg","shopUrl":"korablik","MyName":"Evgenia Kondrakhina","MyPhoto":"logo14717092787.jpg","ShopOwner":1} 

この応答は、時にはめったに例えば、それは近いブラウザの後に起こることはできませんないと、再びそれを開くか、単に理由なしに起こる起こる

Laravel側コード:

public function sendmessageboxShop (Request $Request){ 

    $input= $Request->all(); 
    $me = \App\User::find(\Auth::user()->id); 
    $shopid=$input['Toshop']; 
    $shopforme=\App\shop::findOrFail($shopid); 
    $hefallow = \App\favirotshop::where("shop_id",$shopforme->id) 
           ->where("user_id",$me->id) 
           ->firstOrFail(); 

      if(trim($input['mes'])){ 

           $themessagee=  \App\shopChat::create([ 
             'message' => $input['mes'], 
             'fromuser' => $me->id, 
             'fromShopid' => null, 
             'to_shop_id' => $shopforme->id, 
             'to_user_id' => null, 
             'status' => 0, 

            ]); 



          $themessagee["Created"] =strtotime($themessagee->created_at); 
          $themessagee["shopName"]=$shopforme->name; 
          $themessagee["shopLogo"]=$shopforme->logo; 
          $themessagee["shopUrl"]=$shopforme->friendly_url; 
          $themessagee["MyName"]=$me->name; 
          $themessagee["MyPhoto"]=$me->photolink; 
          $themessagee["ShopOwner"]=$shopforme->foruser; 



           event(new ChatToNode($themessagee)); 
          return response()->json($themessagee); 

           } 

} 

jQueryのサイドコード:

ShopID= $('#forShop').val(); 

        $.ajax({ 
         type: 'POST', 
         url : '/sendmessageboxShop', 
         dataType : "json", 
         data: { 
           Toshop: ShopID, 
           mes:mes 
         }, 
         beforeSend: function() { 

         } 
        }).always(function() { // always executed 

        }) 
         .fail(function(data) { 
         sweetAlert("Oops...", "there was erorr in connection", "error"); 
          }) 
         .done(function($obj) { 


    if($obj) 
     { if($("div").find("[data-logforShop='" + ShopID + "']").is(":visible")){ 


          $('#chat-messages').append('<div class="message right">'+ 
           '<img src="/profilepics/'+$obj.MyPhoto+'" />'+ 
           '<div class="bubble">'+ 
           $obj.message + 
            '<div class="corner"></div>'+ 
            '<span id="timeagodiv" class="modaltime" data-livestamp="'+$obj.created_at+'"></span>'+ 
           '</div>'+ 
          '</div>'); 


          var bottomCoord = $('#chat-messages')[0].scrollHeight; 
          $('#chat-messages').slimScroll({scrollTo: bottomCoord}); 
          $("#messageval").val(''); 

         } 
         else { 

          console.log("no"); 
         } 
} 
         }); 

おかげで、事前

答えて

1

に私はlaravelユーザないんだけど、問題はlaravelコアからである場合には、あなたが追加して、JavaScriptで修正することができますデータフィルタを要求に追加します。

ShopID = $('#forShop').val(); 

$.ajax({ 
    type: 'POST', 
    url: '/sendmessageboxShop', 
    dataType: "json", 
    data: { 
     Toshop: ShopID, 
     mes: mes 
    },dataFilter: function(raw_json){ 
     return raw_json.replace(/[0-9]+\{/, "{"); 
    } 
}) 
....the rest of your code 

これが役立ちます。

+0

この回答をいただきありがとうございます。これはうまくいきますが、私はlaravelの解決策とは思えません。 –

+0

その場合、出力バッファが画面に表示される前に出力バッファをフォーマットするミドルウェアをlaravelに作成する必要があります – Popsyjunior

関連する問題