dimanche 27 août 2017

how to use post method in laravel and ajax

When I use post method using ajax ,it always throws Method not allowed error. Without using ajax ,if use form method post ,it goes to this method.Please help me. My code is

In Router.php

 $this->post('TestPost','DashboardController@TestPostMethod');

In View,ajax is

$.ajax(
{           
type: "POST",
url: 'TestPost',
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function (data) {  
alert('hid post');       

SetHotandWorstData(data,'hotquantity');


},

error: function (msg) {
alert('error');
alert(msg.responseText);
}
});

IN Controller,

function TestPostMethod(Request $request)
{
$hotworstsalesdata = DB::table('100_INVOICEDETAIL')              
    -

    >select('100_INVOICEDETAIL.ITEMCODE','100_INVOICEDETAIL.ITEMNAME',
DB::raw('SUM("100_INVOICEDETAIL"."QTY") as 
salesqty'),DB::raw('SUM("100_INVOICEDETAIL"."AMT") as salesamt'))
    ->groupBy('100_INVOICEDETAIL.ITEMCODE','100_INVOICEDETAIL.ITEMNAME')
    ->orderBy('salesqty')
    ->take(10)
    ->get();
    return Datatables::of($hotworstsalesdata)->make(true);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire