Arunava007
7 months ago

AJAX GET REQUEST USING LARAVEL

Posted 7 months ago by Arunava007

My objective is to show data from database depending upon the dropdown value i select in the same page. Error:: POST method not allowed

I was able to display data in different page but i failed when it comes to the same page in a different div section. Please help me out

My CRD.blade.php


<!DOCTYPE html>
<html>
<head>
    <title>ROBOTICS DESK</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

</head>
<body>


<h1>ROBOTICS</h1>

<form id="myform">
    EVent Name &nbsp;<select name="event" id ="event">
        <option value="" selected="selected">--- Please select ---</option>

        <option id="R1" value="Infinity War">Infinity War</option>
        <option id="R2" value="Terrestrial Terrain">Terrestrial Terrain</option>
        <option id="R3" value="Robo Rugby">Robo Rugby</option>
        <option id="R4" value="Sputnik">Sputnik</option>

    </select>


    <input type="button" name="submit" class="button" value="CHECK TEAM REGISTERED" onclick="check()"><br><br>

    <div id="data"></div>   <br>

</form>

<script>
    function check()
    {
        var str="SOMETHING IS WRONG";
        var event=$("#event").val();

        $.ajax({
            url :'/CRD',
            type:'POST',
            dataType:'html',
            data :{
                'action':'generate',
                'event':event,

            },
            success:function(data){
                if(str==data){
                    $('#data').html(data);
                    //$('#myform')[0].reset();
                }
                else{
                    $('#data').html(data);
                    //$('#myform')[0].reset();
                }
            }
        });
    }

My Controller


<?php

namespace App\Http\Controllers;
use Illuminate\Contracts\Database;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Response;

class CRDController extends Controller
{
    public function index()
    {
//
      return view("CRD");
    }
    public function mycrd(Request $request)
    {
        $data = DB::table('rd1')->where([
            ['domain', '=', $request->domain],
            ['event', '=', $request->event],

        ])->get();
        dd($data);
    }
}


My Routes

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


Please sign in or create an account to participate in this conversation.