2017-08-01 91 views
0

我有一些路線問題。MethodNotAllowedHttpException [AJAX]!

Code: MethodNotAllowedHttpException in RouteCollection.php line 219. 

我使用ajax和laravel 5.1。我嘗試使用谷歌,但我不明白,我嘗試方法「路徑」,並在阿賈克斯更改「類型」「方法」。我嘗試GET,但沒有工作。

我的ajax:

$.ajax({ 
    type: 'POST', 
    url: '/placeBet', 
    dataType: 'json', 
    data: { 
     ammount: ammount, 
     color: color 
    }, 
    headers: { 
     'X-CSRF-TOKEN': $('#_token').val() 
    }, 
    success: function (data) { 
     if (data['color'] == 'red') { 
      var currentPlaced = parseInt($('.user_red').html()); 
      currentPlaced = currentPlaced + parseInt(data['ammount']); 
      $('.user_red').html(currentPlaced); 
     } 
     if (data['placedMuch']) { 
      alertify.error('Max 4 bets in round!'); 
     } 
     if (data['color'] == 'purple') { 
      var currentPlaced = parseInt($('.user_black').html()); 
      currentPlaced = currentPlaced + parseInt(data['ammount']); 
      $('.user_black').html(currentPlaced); 
     } 
     if (data['color'] == 'gold') { 
      var currentPlaced = parseInt($('.user_gold').html()); 
      currentPlaced = currentPlaced + parseInt(data['ammount']); 
      $('.user_gold').html(currentPlaced); 
     } 
     if (data['color'] == 'green') { 
      var currentPlaced = parseInt($('.user_green').html()); 
      currentPlaced = currentPlaced + parseInt(data['ammount']); 
      $('.user_green').html(currentPlaced); 
     } 
     if (data['baaad'] == true) { 
      alertify.error('Niu niu!'); 
      return; 
     } 
     if (data['improvements'] == true) { 
      alertify.error('We are working on improvements.'); 
      return; 
     } 
     if (data['toLow'] == true) { 
      alertify.error('Minimum bet is 200 diamonds!'); 
      return; 
     } 
     if (data['can_bet'] == false) { 
      alertify.error('You have withdraw request pending, you cannot bet!'); 
      return; 
     } 

     if (data['placed'] != false && data['coins'] != false) { 
      var coins = data['coins']; 
      var htmlo = '<div class="chat_message"><div class="top"><div class="right_info"><a href="javascript:void(0);" class="user_name admin">Info Bot</a></div></div><div class="message">You spent ' + ammount + ' diamonds on ' + data['color'] + '.</div></div>'; 
      $('#chatmessages').append(htmlo); 
      $('.recents_box').mCustomScrollbar("scrollTo", 'bottom'); 
      $({countNum: $('#currentBallance').html()}).animate({countNum: coins}, { 
       duration: 1000, 
       easing: 'linear', 
       step: function() { 
        $('#currentBallance').html(parseFloat(this.countNum).toFixed(0)) 
       }, 
       complete: function() { 
        $('#currentBallance').html(parseFloat(this.countNum).toFixed(0)) 
       } 
      }); 
     } else if (data['placed'] != false && data['coins'] == '0') { 
      var coins = data['coins']; 
      var htmlo = '<div class="chat_message"><div class="top"><div class="right_info"><a href="javascript:void(0);" class="user_name admin">Info Bot</a></div></div><div class="message">You spent all your diamonds on ' + data['color'] + '.</div></div>'; 
      $('#chatmessages').append(htmlo); 
      ('.recents_box').mCustomScrollbar("scrollTo", 'bottom'); 
      $({countNum: $('#currentBallance').html()}).animate({countNum: coins}, { 
       duration: 1000, 
       easing: 'linear', 
       step: function() { 
        $('#currentBallance').html(parseFloat(this.countNum).toFixed(0)) 
       }, 
       complete: function() { 
        $('#currentBallance').html(parseFloat(this.countNum).toFixed(0)) 
       } 
      }); 

      // swal('Yea', 'You placed a bet to ' + color + '. Your current coins are : ' + coins + '!', 'success'); 
      // $('#betammount').val(0); 
     } else { 
      if (data['logged'] == false) { 
       alertify.error('You need to be log in to use this option!'); 
      } else if (data['coins'] == false) { 
       alertify.error('You are not that rich!'); 
       // $('#betammount').val(0); 
      } else if (data['coins'] == '0') { 
       alertify.error('You are empty!'); 
       //$('#betammount').val(0); 
      } 

     } 
    } 

}); 

我的路線:

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

我RoulleteController:

public function placeBet(Request $request) 
{ 

    $info = []; 

    if (Auth::check()) { 

     $lastID = DB::select("SELECT * FROM roulette_history ORDER BY id DESC LIMIT 1"); 
     $roundID = $lastID[0]->id; 
     $steamID = Auth::user()->steamId64; 
     $ammount = $request->All()['ammount']; 
     $getCountPlaced = \App\placedBets::where('gameID', $roundID)->where('userID64', Auth::user()->steamId64)->count(); 
     if($getCountPlaced > 3) { 
      $info['placedMuch'] = true; 
      $info = json_encode($info); 
      return $info; 
     } 
     if($ammount < 1 || !is_numeric($ammount)) { 
      $info['baaad'] = true; 
      $info = json_encode($info); 
      return $info; 
     } 
     if ($ammount < 200) { 
      $info['toLow'] = true; 
      $info = json_encode($info); 
      return $info; 
     } 
     if(Auth::user()->global_banned > 0) { 
      $info['baaad'] = true; 
      $info = json_encode($info); 
      return $info; 
     } 
     $color = $request->All()['color']; 
     if($color == 'black') { 
      $color = 'purple'; 
     } 

     $user_info = \App\User::where('steamId64', Auth::user()->steamId64)->first(); 
     $active_ofer = \App\ofers::where('userID', Auth::user()->steamId64)->count(); 
     $info['active_ofer'] = $active_ofer; 

     $user_coins = $user_info->coins; 
     if ($user_coins < $ammount) { 
      $info['coins'] = false; 
      $info['placed'] = false; 

     } else { 
      $user_coins = $user_coins - $ammount; 
      $siteProfit = \App\profit::first(); 
      $siteProfitTotal = $siteProfit->siteProfit; 
      $siteProfitTotal = intval($siteProfitTotal) + intval($ammount); 
      $updateProfit = DB::update("UPDATE siteProfit SET siteProfit='$siteProfitTotal'"); 
      $user_update = \App\User::where('steamId64', Auth::user()->steamId64)->update(['coins' => $user_coins]); 

      $info['coins'] = $user_coins; 
      $active_bet = DB::select("SELECT * FROM roulette_history ORDER BY id DESC LIMIT 1"); 
      $game_id = $active_bet[0]->id; 
      $placed = DB::insert('insert into placed_bets (color, userID64, ammount, gameID, avatar,url,nick,isStreamer,streamLink) values (?, ?, ?, ?,?,?,?,?,?)', [$color, $steamID, $ammount, $game_id, $user_info->avatar, $user_info->url, $user_info->nick,$user_info->isStreamer,$user_info->steamLink]); 
      $info['placed'] = true; 
      $info['ammount'] = $ammount; 
      $info['color'] = $color; 
      $info['count'] = $getCountPlaced; 
     } 
     $info['logged'] = true; 
    } else { 
     $info['coins'] = 0; 
     $info['logged'] = false; 
     $info['placed'] = false; 
    } 
    $info = json_encode($info); 
    return $info; 
} 

如果妳需要源,我可以得到我們!

回答

0

在你的Ajax調用,改變

$.ajax({ 
    type: 'POST', 

$.ajax({ 
    method: 'POST', 
+0

我測試類型的方法,而不是工作 – Snegan

相關問題